Public Class frmMain
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case e.CloseReason
Case CloseReason.ApplicationExitCall
'The user perfromed an action that caused your code to call Application.Exit.
'You could go either way here but I'd suggest that you shouldn't be calling Application.Exit
'if you don't actually want the application to exit. In that case close the main form instead.
e.Cancel = False
Case CloseReason.FormOwnerClosing
'This form is a modeless dialogue, which you shouldn't be minimising to the system tray anyway.
e.Cancel = False
Case CloseReason.MdiFormClosing
'This form is an MDI child form, which you shouldn't be minimising to the system tray anyway.
e.Cancel = False
Case CloseReason.None
'If the reason can't be determined then something funky is going on so I'd suggest you let the form close.
e.Cancel = False
Case CloseReason.TaskManagerClosing
'The user pressed the End Task button on the Applications tab (NOT the Processes tab) of the Task Manager.
'You could go either way here too. It really depends on your app and if you don't want the user to be able to exit
'this way. I'd suggest letting the form close but there would definitely be legitimate reasons for preventing it.
e.Cancel = False
Case CloseReason.UserClosing
'The user clicked the Close button on the title bar, pressed Alt+F4, selected Close from the
'system menu or performed some action that caused your code to call the form's Close method.
'Don't let the form close.
e.Cancel = True
Me.Visible = False
' Me.Hide()
Me.ntfyI.Visible = True
' Me.ntfyI.ShowBalloonTip(1000)
Case CloseReason.WindowsShutDown
'Windows is shutting down.
'Definitely let the form close or you'll prevent Windows shutting down normally.
e.Cancel = False
End Select
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ntfyI_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ntfyI.MouseDoubleClick
Me.WindowState = FormWindowState.Normal
Me.Visible = True
Me.ntfyI.Visible = False
End Sub
Private Sub cmbExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbExit.Click
Application.Exit()
End Sub
Private Sub frmMain_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
If Me.WindowState = FormWindowState.Minimized Then
Me.Visible = False
Me.ntfyI.Visible = True
End If
End Sub
End Class