相关疑难解决方法(0)

退出按钮以在C#中关闭Windows窗体表单

我尝试过以下方法:

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if ((Keys) e.KeyValue == Keys.Escape)
        this.Close();
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

然后我尝试了这个:

protected override void OnKeyDown(KeyEventArgs e)
{
    base.OnKeyDown(e);
    if (e.KeyCode == Keys.Escape)
        this.Close();
}
Run Code Online (Sandbox Code Playgroud)

仍然没有任何工作.

我的Windows窗体表单属性上的KeyPreview设置为true ...我做错了什么?

c# winforms

87
推荐指数
4
解决办法
6万
查看次数

标签 统计

c# ×1

winforms ×1