实现效果:
知识运用:
KeyEventArgs类的KeyData属性 //获取KeyDown或KeyUp事件的键数据
public Keys KeyData {get;}
实现代码:
private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Escape) { if (MessageBox.Show("你确定要关闭吗?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { Application.Exit(); } } }