Ask Your Question
2

What is the procedure for minimizing an application to the system notification tray in XAML VB?

asked 2022-09-03 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-12-02 02:00:00 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-03 11:00:00 +0000

Seen: 9 times

Last updated: Dec 02 '21