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

后端 未结 5 1562
离开以前
离开以前 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:12

    Paste this code into the "On Key Down" Property of your form, also make sure you set "Key Preview" Property to "Yes".

    If KeyCode = vbKeyEscape Then DoCmd.Close acForm, "YOUR FORM NAME"
    

提交回复
热议问题