Escape button to close Windows Forms form in C#

后端 未结 8 1236
心在旅途
心在旅途 2020-12-02 06:15

I have tried the following:

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if ((Keys) e.KeyValue == Keys.Escape)
               


        
8条回答
  •  一向
    一向 (楼主)
    2020-12-02 06:55

    By Escape button do you mean the Escape key? Judging by your code I think that's what you want. You could also try Application.Exit(), but Close should work. Do you have a worker thread? If a non-background thread is running this could keep the application open.

提交回复
热议问题