Below is an example of how to create a system tray icon in a Windows Application (WinForms) using c# and vb.NET.

Here are the steps to follow to complete this tutorial.

Step 1

Create a windows form application

create-winforms-app

Step 2

Add a NotifyIcon to the main form

NotifyIcon

Step 3

Add an icon to the NotifyIcon

Note: it’s vital to add an icon to the NotifyIcon. Otherwise, the NotifyIcon will not show up.

Add-icon

Step 4

Add the code below to the Form Load event

C#

        private void frm_Load(object sender, EventArgs e)
        {
       
            notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;

            notifyIcon1.BalloonTipText = "Welcome to TutorialsPanel.com!!";

            notifyIcon1.BalloonTipTitle = "Welcome Message";

            notifyIcon1.ShowBalloonTip(2000);
        }

VB.NET

Private Sub frm_Load(sender As Object, e As EventArgs)

	notifyIcon1.BalloonTipIcon = ToolTipIcon.Info

	notifyIcon1.BalloonTipText = "Welcome to TutorialsPanel.com!!"

	notifyIcon1.BalloonTipTitle = "Welcome Message"

	notifyIcon1.ShowBalloonTip(2000)
End Sub

Step 5

Run the application

notify-icon

Step 6

Now let add a Double Click event on the NotifyIcon. Double click on the NotifyIcon in the design view, and then add the code below to the event

C#

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("Someone just double clicked on the icon!");
         
            notifyIcon1.Visible = false;
        }

VB.NET

Private Sub notifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs)
	MessageBox.Show("Someone just double clicked on the icon!")
        notifyIcon1.Visible = False
End Sub

Step 7

Double Click on the icon in the system tray

notifyicon-double-click

Related Article:

Get Computer Name Using VB.NET

Get computer name using C#

Last modified: March 8, 2019

Comments

Thanks for the tutorial.

So can you show the tray icon when the form minimizes?

Write a Reply or Comment

Your email address will not be published.