I need to close an mdi child with Esc key. I tried using keydown and keypress events, but i cant even get the form respond to those events when pressing any key.
try this
private void Form_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
or make use of
Form.CancelButton Property - Gets or sets the button control that is clicked when the user presses the ESC key.
Set the Property of the Form KeyPreview=True
and go with Keydown Event
if (e.KeyCode == Keys.Escape){
this.Close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With