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;//取消關閉事件 } }