在窗体的关闭事件FormClosing中进行判断,FormClosing事件每当用户关闭窗体时,在窗体已关闭并指定关闭原因前发生

 1         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 2         {
 3             DialogResult r = MessageBox.Show("是否关闭窗体?", "提示", MessageBoxButtons.YesNo);
 4             if (r == DialogResult.Yes)//点击“是”按钮
 5             {
 6                 e.Cancel = false;//事件的取消为假,关闭窗体
 7             }
 8             else
 9             {
10                 e.Cancel = true;//事件的取消为真,不关闭窗体
11             }
12         }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-02-08
  • 2021-12-06
  • 2021-05-23
  • 2021-08-02
猜你喜欢
  • 2022-12-23
  • 2022-02-19
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案