Question Prevent Exit without hindering windows restart

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
Is there a way for a program to not exit when you hit the close X box but will exit if window is restarting or shutting down? I can do a e.cancel in formClosing but when windows is restarting, i need to force restart.
 
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    If e.CloseReason <> CloseReason.WindowsShutDown Then
        MessageBox.Show("Sorry, no closey for you!")
        e.Cancel = True
    End If
End Sub
You should check out all the possible values for e.CloseReason.
 
Back
Top