Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a step-by-step procedure for minimizing an application to the system notification tray in XAML VB:

  1. First, add a reference to the System.Windows.Forms namespace in your project.

  2. Next, create a NotifyIcon object and set its properties. The NotifyIcon object represents the icon that will be displayed in the system notification tray.

Dim notifyIcon As New NotifyIcon()
notifyIcon.Icon = New System.Drawing.Icon("icon.ico")
notifyIcon.Visible = True
  1. Next, handle the Form's Resize event and check if the WindowState property is set to FormWindowState.Minimized.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Resize
  If Me.WindowState = FormWindowState.Minimized Then
    ' Minimize to system notification tray
  End If
End Sub
  1. Add code inside the Resize event handler to minimize the form to the notification tray. This can be done by setting the Visible property of the form to False, and displaying the NotifyIcon.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.Visible = False
        notifyIcon.ShowBalloonTip(500)
    End If
End Sub
  1. Finally, add code to handle the NotifyIcon's MouseDoubleClick event, which will restore the form to its original size.
Private Sub notifyIcon_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles notifyIcon.MouseDoubleClick
    Me.Visible = True
    Me.WindowState = FormWindowState.Normal
End Sub

With these steps, your application will be able to minimize to the system tray and restore when double-clicked.