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

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

    Button cancelBTN = new Button();
    cancelBTN.Size = new Size(0, 0);
    cancelBTN.TabStop = false;
    this.Controls.Add(cancelBTN);
    this.CancelButton = cancelBTN;
    

提交回复
热议问题