在窗体的Closing事件中加入确认代码。
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("您确认退出吗?", "www.cnblogs.com/jihua", MessageBoxButtons.YesNoCancel) == System.Windows.Forms.DialogResult.Yes) { Dispose(); Application.Exit(); } else { e.Cancel = true; } }