c# 退出时加一个确认窗口(为什么 e.Cancel=true 不让用呢)
提升 e 不包含 Cancel 的定义?????? 我主要想实现点击CANCEL的时候,消息框消失,窗体还在就行
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (MessageBox.Show("请您确认是否退出(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Application.Exit();
}
else
{
e.Cancel=true;
}
------解决方案--------------------
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
DialogResult r = MessageBox.Show("确定要退出程序?", "关闭确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (r != DialogResult.OK)
{
e.Cancel = true;
}
}
}