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/