hi guys! help please. How can i close the window form when the user press the scape button?
Printable View
hi guys! help please. How can i close the window form when the user press the scape button?
In the keydown event of your form.
if(e.keycode == Keys.Escape) this.Close();
and set the keypreview property of the form to true.
Thaks for that but, i dont have thebut i tried the Keychar but i have a problem comparing it becuase they have different typesCode:e.Keycode property
is of type char andCode:e.Keychar
is of type keys. I've tried parsing them but i have no luck...help pleaseCode:Keys.Escape
Code:private void FrmSearch_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Keys.Escape)
MessageBox.Show("you press escape.");
}
keydown event not keypress.