Click to See Complete Forum and Search --> : C#.NET2008 Cannot close FRMSALES


LennieKuah
March 29th, 2010, 12:07 AM
Hi Good Guys,

Please help me, I need your help.

I am a Newbie writing C#.Net 2008 Window Application.
In the FRMSALES, to exit this form the users can either click on BTNEXIT or press the ESC Key but both of them are not working.

Here is the error message:

'System.EventArgs' does not contain a definition for 'KeyCode' and no extension method 'KeyCode' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)

Here is the coding (C#.NET 2008)

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

private void btnexit_Click(object sender, System.EventArgs e)
{
this.Close;
}

private void FrmMain_KeyDown(Object sender, System.EventArgs e)
{
if (e.KeyCode = Keys.Escape)
this.Close;
}

Thank you,

Cheers,
Lennie

dannystommen
March 29th, 2010, 03:39 AM
This can be done much easier.

You only need the btnExit_click event. To make the form closing on Escape, set the form's CancelButton property to btnExit (or whatever you button is called)

LennieKuah
March 29th, 2010, 03:46 AM
Hi dannyStommen,
Thank you very much for sharing your knowledge with me. You are awesome and generous in sharing information. I have edited my code and tried it out and it's working. Yaaaa.....Hoooooo...
I have learned something new as well.

I am so glad to met you here. After my coding is working, I am trying to create a CONNECTTIONSTRING CLASS to be used by all the programs. I may come to you again asking for help.

Thank you very much for your help.
You have a Good Day.

Cheers,
Lennie