【问题标题】:.NET Canceling closing of a form prevents it from closed on Windows shutdown.NET 取消关闭窗体可防止它在 Windows 关闭时关闭
【发布时间】:2012-07-27 17:25:21
【问题描述】:
 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 都会向窗口发送关闭消息,这并没有真正帮助我。我可以想到一些其他的方法,但应该有一个“清晰”的认识方式。

提前致谢:)

【问题讨论】:

    标签: windows vb.net shutdown formclosing


    【解决方案1】:

    还有一个密切的原因:

    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
    

    【讨论】:

      【解决方案2】:

      您应该能够从这个list 实现一个关闭原因枚举。 这将允许您这样做,以便您的计算机将关闭。您必须在 e.CloseReason 中实现 WindowsShutDown 和/或 TaskManagerClosing 枚举。

      【讨论】:

      • 谢谢!好像我从来没有关注过closereason :)
      猜你喜欢
      • 2018-01-11
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多