实现效果:

  按Esc键实现关闭窗体

知识运用:

  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();
                }
            }
        }

 

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-15
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
相关资源
相似解决方案