Click here to Skip to main content
15,878,945 members
Articles / Programming Languages / C#

NotifyIcon in System Tray with Context Menu Using C#

Rate me:
Please Sign up or sign in to vote.
2.53/5 (41 votes)
5 Oct 2007CPOL 169.9K   110   56   19
This is a small application which shows how we to use NotifyIcon in the system tray and also use a menu control with it.

Screenshot - systemTray.jpg

Introduction

Using the NotifyIcon component, we can put our application icon on the system tray and use a ConextMenuStrip to control the menu in the system tray.

Background

The function of the ConextMenuStrip is the similar to that of the menu bar. It will appear only when we right click for it.

Screenshot - conextmenu.jpg

Using the code

The code for this application is very simple, you just need to know how to use it. Code for restore application, open settings, close from system tray are listed in this section:

C#
namespace NotifyIcon
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Use_Notify(); // Setting up all Property of Notifyicon 
        }

        private void Use_Notify()
        {
            MyNotify.ContextMenuStrip = contextMenuStrip1; 
            MyNotify.BalloonTipText = "This is A Sample Application";
            MyNotify.BalloonTipTitle = "Your Application Name";
            MyNotify.ShowBalloonTip(1); 
        }

        private void Form1_Resize(object sender, System.EventArgs e)
        {
            // Hide The Form when it's minimized
            if (FormWindowState.Minimized == WindowState)
                Hide();
        }
        private void MyNotify_DoubleClick(object sender, System.EventArgs e)
        {
            // Show the form when Dblclicked on Notifyicon
            Show();
            WindowState = FormWindowState.Normal;
        }
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Will Close Your Application 
            MyNotify.Dispose();
            Application.Exit();
        }

        private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Will Restore Your Application 
            Show();
            WindowState = FormWindowState.Normal;
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Settings 1
            MessageBox.Show("Your Application Settings 1");
        }

        private void settings2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Settings 2
            MessageBox.Show("Your Application Settings 2");
        }
    }
}

You can apply this in any of your applications.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog : http://abhijitjana.net
Web Site : http://dailydotnettips.com
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

Comments and Discussions

 
PraiseThanks Pin
Ertuğrul Baran2-Jul-21 10:49
Ertuğrul Baran2-Jul-21 10:49 
Questionicon Pin
smpaliwal29-Mar-13 21:18
smpaliwal29-Mar-13 21:18 
GeneralMy vote of 1 Pin
Jetro2236-Dec-12 2:43
Jetro2236-Dec-12 2:43 
QuestionNot bad! Pin
BruceL5-Jul-11 3:11
BruceL5-Jul-11 3:11 
GeneralMy vote of 1 Pin
Member 32246509-Mar-11 22:30
Member 32246509-Mar-11 22:30 
GeneralMy vote of 4 Pin
hoerst23-Oct-10 0:15
hoerst23-Oct-10 0:15 
GeneralMy vote of 1 Pin
JohnAndre24-Aug-10 23:09
JohnAndre24-Aug-10 23:09 
GeneralMy vote of 5 Pin
Member 43370486-Aug-09 22:03
Member 43370486-Aug-09 22:03 
GeneralRe: My vote of 5 Pin
Abhijit Jana9-Aug-09 21:33
professionalAbhijit Jana9-Aug-09 21:33 
GeneralMy vote of 1 Pin
Ingvarr24-Jul-09 1:06
Ingvarr24-Jul-09 1:06 
GeneralRe: My vote of 1 Pin
Abhijit Jana26-Sep-09 22:37
professionalAbhijit Jana26-Sep-09 22:37 
General[My vote of 1] where is the code Pin
Donsw28-Jun-09 14:43
Donsw28-Jun-09 14:43 
GeneralMy vote of 1 Pin
ayo1016-Jun-09 10:31
ayo1016-Jun-09 10:31 
GeneralMy vote of 1 Pin
Pri N T8-Jan-09 17:02
Pri N T8-Jan-09 17:02 
GeneralWhere's the code for 'MyNotify' Pin
Mark19753-Apr-08 14:37
Mark19753-Apr-08 14:37 
GeneralRe: Where's the code for 'MyNotify' Pin
#realJSOP20-Apr-08 4:13
mve#realJSOP20-Apr-08 4:13 
GeneralNotify icon stays in tray... Pin
Mark James Newman11-Oct-07 12:53
Mark James Newman11-Oct-07 12:53 
GeneralRe: Notify icon stays in tray... Pin
Abhijit Jana15-Oct-07 19:14
professionalAbhijit Jana15-Oct-07 19:14 
GeneralRe: Notify icon stays in tray... Pin
Mark James Newman16-Oct-07 3:31
Mark James Newman16-Oct-07 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.