winform 中点击"X"弹出提示是否关闭(退出整个应用程序代码):
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.ApplicationExitCall)
{
DialogResult re = MessageBox.Show("确定要退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (re == DialogResult.Yes)
{
e.Cancel = false;
Application.Exit();
}
else
{
e.Cancel = true;
}
}
}
网友评论