Show and Hide Windows Form in System Tray

Posted by dragon on Friday, 9 September 2011

type='html'>How to show and hide your form in windows system tray.

1. Add NotifyIcon class in your project (System.Windows.Forms.NotifyIcon) and drag it into form.

2. Change NotifyIcon properties.
BalloonTipIcon = Info
BalloonTipText = Running
Change Icon
Text = Running Your Program
Visible = True

3. Add code in Event Form1_Resize.

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Resize
' If minimize form that will show in system tray.
If System.Windows.Forms.FormWindowState.Minimized = WindowState Then
sysMonTray.ShowBalloonTip(5, "Running", "Running Your Program", ToolTipIcon.Info)
End If
End Sub

4. Add code in Event NotifyIcon_Click to hide and show form.

Private Sub sysMonTray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles sysMonTray.Click

If Me.Visible Then
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
Me.StartPosition = FormStartPosition.CenterScreen
End If

End Sub

{ 0 comments... read them below or add one }

Post a Comment