如果我的应用程序正在运行,如何在Windows关闭时发出警告 [英] How to give warning at windows shut down if my app is running

查看:82
本文介绍了如果我的应用程序正在运行,如何在Windows关闭时发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Windows关闭时(按用户)如何显示警告消息和

停止Windows关闭过程unles用户确认是否正常。



谢谢

Hi,
At Windows Shutdown (by user) how can I display a warning message and
halt the process of windows shutdown unles user confirms if it is ok.

Thanks

推荐答案

参见Form.FormClosing事件 [ ^ ]

检查FormClosingEventArgs的CloseReason属性,如果是CloseReason.WindowsShutDown然后将e.Cancel设置为True则应该阻止表单立即关闭。

然后,你可以使用
See the Form.FormClosing event[^]
Check the CloseReason property of the FormClosingEventArgs, if it is CloseReason.WindowsShutDown then set e.Cancel to True then it should prevent the form closing immediately.
Then, you can stop shutdown by using
Process.Start("shutdown", "-a")

我没有在Win8或Win10中试过这个,但是它应该仍然有用。

I haven't tried this in Win8 or Win10, but it should still work.


这篇关于如果我的应用程序正在运行,如何在Windows关闭时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆