实现窗体的FormClosing 事件,在事件里面填写退出的功能代码!!
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (DialogResult.Yes == MessageBox.Show("是否退出系统?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
Environment.Exit(0);
else
e.Cancel = true;
}