In this article I will explain with an example, how to create a System Tray Windows (WinForms) Desktop Application using Notification Icon in C# and VB.Net.
First Add Form Resize event to the Windows Form using the Properties Windows as shown below
Then from the Toolbox add the NotifyIcon control to the Windows Form as shown in the screenshot below
Then Right Click the NotifyIcon control and click Choose Icon and choose the Icon (.ICO) file for the application.
Once all the above is done paste the following code
C#
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.BalloonTipText = "Application Minimized.";
notifyIcon1.BalloonTipTitle = "ASPSnippets";
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(1000);
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
NotifyIcon1.BalloonTipText = "Application Minimized."
NotifyIcon1.BalloonTipTitle = "ASPSnippets"
End Sub
Private Sub Form1_Reseize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
If WindowState = FormWindowState.Minimized Then
ShowInTaskbar = False
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(1000)
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
ShowInTaskbar = True
NotifyIcon1.Visible = False
WindowState = FormWindowState.Normal
End Sub
Finally double click on the NotifyIcon control and paste the following code in the double click event
C#
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
VB.Net
Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
ShowInTaskbar = True
NotifyIcon1.Visible = False
WindowState = FormWindowState.Normal
End Sub
Downloads
You can download the code in VB.Net and C# using the following download link below