1. 添加引用:
using System.ComponentModel;
2.添加窗体Closing事件
private void Form1_Closing( object sender, CancelEventArgs e )
{
string text = "确定退出程序?";
string caption = "关闭程序";
if (MessageBox.Show( text, caption, MessageBoxButtons.YesNo) == DialogResult.No )
e.Cancel = true;
}