private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //主窗体关闭时,弹出对话框。判断对话框的返回值(即用户的操作是什么)是OK还是Cancel!
            if (DialogResult.OK == MessageBox.Show("确定要关闭吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                //为保证Application.Exit();关闭主窗体时不再弹出对话框提示,所以将FormClosing事件取消
                this.FormClosing -= new FormClosingEventHandler(this.Form1_FormClosing);
                System.Windows.Forms.Application.Exit();//退出整个应用程序
                System.Environment.Exit(0);
            }
            else
            {
                e.Cancel = true;//取消关闭事件
            }
        }

 

相关文章:

  • 2022-01-19
  • 2021-11-23
  • 2021-11-23
  • 2021-10-21
  • 2022-12-23
  • 2021-11-08
  • 2021-12-08
  • 2022-02-10
猜你喜欢
  • 2021-11-14
  • 2022-01-23
  • 2021-11-23
  • 2022-12-23
  • 2021-10-01
  • 2021-04-10
  • 2021-11-23
相关资源
相似解决方案