添加form的FormClosing事件
/// <summary>
/// 主窗口自带的关闭按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result;
result = MessageBox.Show("确定退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
Application.ExitThread();
}
else
{
e.Cancel = true;
}
}