Click here to Skip to main content
Licence CPOL
First Posted 5 Oct 2007
Views 94,034
Bookmarked 48 times

NotifyIcon in System Tray with Context Menu Using C#

By | 5 Oct 2007 | Article
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:

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)

About the Author

Abhijit Jana

Software Developer (Senior)

India India

Member

Follow on Twitter Follow on Twitter
.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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNot bad! PinmemberBruceL3:11 5 Jul '11  
GeneralMy vote of 1 PinmemberMember 322465022:30 9 Mar '11  
GeneralMy vote of 4 Pinmemberhoerst0:15 23 Oct '10  
GeneralMy vote of 1 PinmemberJohnAndre23:09 24 Aug '10  
GeneralMy vote of 5 PinmemberMember 433704822:03 6 Aug '09  
GeneralRe: My vote of 5 PinmvpAbhijit Jana21:33 9 Aug '09  
GeneralMy vote of 1 PinmemberIngvarr1:06 24 Jul '09  
GeneralRe: My vote of 1 PinmvpAbhijit Jana22:37 26 Sep '09  
General[My vote of 1] where is the code PinmemberDonsw14:43 28 Jun '09  
GeneralMy vote of 1 Pinmemberayo1010:31 16 Jun '09  
GeneralMy vote of 1 PinmemberPri N T17:02 8 Jan '09  
GeneralWhere's the code for 'MyNotify' PinmemberMark197514:37 3 Apr '08  
GeneralRe: Where's the code for 'MyNotify' PinmvpJohn Simmons / outlaw programmer4:13 20 Apr '08  
GeneralNotify icon stays in tray... PinmemberMark James Newman12:53 11 Oct '07  
GeneralRe: Notify icon stays in tray... PinmemberAbhijit Jana19:14 15 Oct '07  
GeneralRe: Notify icon stays in tray... PinmemberMark James Newman3:31 16 Oct '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 6 Oct 2007
Article Copyright 2007 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid