1.将Form窗体属性KeyPreview改True;
2.添加Form窗体KeyPress事件:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
this.Close();
Application.Exit();
}
}
以上2步即可完美解决Form窗体按Esc键关闭窗体。