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;//取消关闭事件 } }