首先在form窗体属性、事件中找到 Closing事件 双击
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("系统提示", "是否退出?", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
System.Environment.Exit(0);
}
else
e.Cancel = true;//取消事件的值
}