C# version here.
In previous versions minimising to the system tray instead of closing a form was a hassle. You had to mess about checking whether the system was shutting down, etc. or else your app would prevent Windows from ever closing. In .NET 2.0 that process is simplified consideralbly:
VB Code:
Private Sub Form1_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
'The user has requested the form be closed so mimimise to the system tray instead.
e.Cancel = True
Me.Visible = False
Me.NotifyIcon1.Visible = True
End If
End Sub
This will minimise the form to the system tray if the user requests the close by clicking the Close button on the title bar, selecting Close from the system menu, pressing Alt+F4 or performing some action that causes your code to call the form's Close method. All other reasons for closure, including calling Application.Exit or Windows shutting down, will cause the form to actually close.
I only just discovered the CloseReason property myself, so I thought I'd share it as others may not be aware of it either.