This is not a good way to close a window. If you show a window as modal (via
ShowDialog
), you need to use
CancelButton
; and the form will close itself on escape:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.cancelbutton.aspx[
^].
And if the form is not modal, you should never close it with Escape, as it will violated expected UI style and can cause loss of user's work, by apparent reasons.
—SA