How to make a form close when pressing the escape key?

后端 未结 5 1557
离开以前
离开以前 2021-01-30 19:31

I have a small form, which comes up when I press a button in a Windows Forms application.

I want to be able to close the form by pressing the escape key. How could I do t

5条回答
  •  不思量自难忘°
    2021-01-30 20:15

    If you have a cancel button on your form, you can set the Form.CancelButton property to that button and then pressing escape will effectively 'click the button'.

    If you don't have such a button, check out the Form.KeyPreview property.

提交回复
热议问题