windows - .NET 取消关闭表单会阻止它在 Windows 关闭时关闭

标签 windows vb.net shutdown formclosing

 Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    e.Cancel = True
    Me.WindowState = FormWindowState.Minimized
End Sub

您好!

我正在使用上面这个简单的代码。但是,如果在我关闭计算机时应用程序处于打开状态,Windows 会等到它关闭或要我终止它才能继续。我无法找到一种方法来了解用户是在尝试关闭应用程序还是 Windows。我所知道的是,在这两种情况下,Windows 都会向窗口发送关闭消息,这对我没有帮助。我可以想到其他一些方法,但应该有一种“清晰”的了解方式。

提前致谢:)

最佳答案

还有一个很接近的原因:

Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs)
  If e.CloseReason <> CloseReason.WindowsShutDown Then
    e.Cancel = True
    Me.WindowState = FormWindowState.Minimized
  End If
End Sub

关于windows - .NET 取消关闭表单会阻止它在 Windows 关闭时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11692666/

相关文章:

c# - 如何避免序列化 float 组属性

r - 这是 R 3.5 中的错误吗?

vb.net - 使用内联 IF 语句 vb.net

java - 在 Java 中捕获多个 Ctrl+C 按键以进行正常和强制关机

c# - 使用 .NET 关闭前保存状态

c# - 在 Windows 应用程序的 EXE 中本地存储数据的最佳方法是什么

c++ - 如何模拟鼠标移动

mysql 数据读取器

sql - 如何在 vb.net 代码中使用 SQL Server 存储过程中的 OUT 参数

linux - 停止和关机