设置了 Closing 事件中的 e.Cancle = true;Windows无法关机或重启系统...请教各位!

supper_lxm 2007-03-28 12:09:49
我写的一个WinForm应用程序,在Closing事件中,将e.Cancle设置成true,则Windows无法关机和重启系统...不知如何解决.特来请教!多谢各位!
...全文
350 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
碼上道 2008-09-10
  • 打赏
  • 举报
回复
学习了,3Q
navysong 2007-03-28
  • 打赏
  • 举报
回复
e.Cancel
学习了
哈哈007哈 2007-03-28
  • 打赏
  • 举报
回复
上面正解
txwd0033 2007-03-28
  • 打赏
  • 举报
回复
学习
北京的雾霾天 2007-03-28
  • 打赏
  • 举报
回复
将e.Cancle设置成true就是为了不让系统关闭或重启,
当满足条件了再设置为False就是了,比如:

protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (MessageBox.Show("确定要关闭吗?", MessageBoxButtons.OKCancel) != DialogResult.OK)
{
e.Cancel = true;
}
}
sz709 2007-03-28
  • 打赏
  • 举报
回复
学习..
vrhero 2007-03-28
  • 打赏
  • 举报
回复
当然是这样...你得判断一下不能总设为true...

.NET 2.0 中 Closing 事件已过时,不应该再使用,用 FormClosing 事件取代...
通过事件数据中的 CloseReason 值可判断引起该事件的原因...


......

switch(e.CloseReason)
{
case CloseReason.ApplicationExitCall:
case CloseReason.TaskManagerClosing:
case CloseReason.WindowsShutDown:
e.Cancel=false;
break;
default:
e.Cancel=true;
break;
}

......

111,088

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧