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
Hello!
I am using this simple code above. However if the application is open while I am shutting down the computer, Windows waits until it's closed or wants me to terminate it in order to continue. I couldn't find a way to know if the user is trying to close application or the Windows is. All I know is, in both situations Windows sends close message to the window and this doesn't really help me. I can think of some other ways yet there should be a "clear" way of knowing.
Thanks in advance :)
There is also a close reason:
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
You should be able to implement a close reason enumeration from this list. This will allow you to make it so that your computer will shutdown. You will have to implement the WindowsShutDown and/or TaskManagerClosing enumeration into your e.CloseReason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With