Putting an Application Into The Windows Taskbar Notification Area Using C#

Introduction

In this article we will build a very simple Windows Forms application that will enable your application to be in the Taskbar Notification Area.

This is a demo application that will just show you how to implement the Notification Class as well as the mere implementation of the ContextMenuStrip Class.

Procedures

Step 1: Create a new “Windows Forms Application” in Visual Studio and name it as you choose (I here named it NotificationTray).

Now a new form is created.

Step 2: Add a Button Control to your form and resize the window, also try to add an icon for your application as you choose. Your form will look like this:

Form

Step 3: Navigate to the toolbox and add the "NotifyIcon" control (for Notification Class) to your project. Similarly add the "ContextMenuStrip" control (used to show some Context Menu) to your project.

As you add the "ContextMenuStrip" control you will see something like this:
 
NotifyIcon 
 
On your form window now just enter the name of Menu you want to be in the "Type Here" Block. (I used "Exit" that will be visible when we right-click on the App icon in the Taskbar Notification Area to exit the application).Then just double-click on the Exit Menu to create the Click Event for us.

When you are done with all these things just go to the property window of the "NotifyIcon" control and in the "ContextMenuStrip" click on the drop down list, it will show the "ContextMenuStrip" control name that you have added previously to your project, you need to just select that.
 
ContextMenuStrip

Now in the "Icon" tab add an Icon that will be visible in the Taskbar Notification Area.
 
Notification tray

Step 4: After you have done with all these things, it's time to code for the Notification to be appear. Just navigate to the Button control Click Event that you added to your project and add the following code:
 

private void buttonNotify_Click(object sender, EventArgs e)

{

    //Shows the Text whenever Mouse is Hover on the

   // Application Icon

   notifyIcon1.Text = "Notify Me";

   //Set the Notification visibility to true

   notifyIcon1.Visible = true;

   //Calling the ShowBallonTip method which

   // takes 4 arguments:

   //1-For how much time the Popup will be shown

   // (I have set here 500 ms)

   //2-Popup Title that is the text shown on the Head

   // of Popup

   //3-Text on the popup

   //4-Icon for the Popup (I have chosen the Info Icon)

  notifyIcon1.ShowBalloonTip(500,"First Notify

       App","Application is in Notification

               Tray",ToolTipIcon.Info);

    //Instead of using ShowBallonTip you can also use

    // different properties of it like:

   // notifyIcon1.BalloonTipText   

  // notifyIcon1.BalloonTipTitle and so on...

  //Creating Event When the Icon is Double Clicked

  // in the Notification Tray

  notifyIcon1.DoubleClick += new

      EventHandler(notifyIcon1_DoubleClick);

   //Hiding the Original Window

   this.Hide();          

}

Step 5: One thing you should notice is that we have added a "DoubleClick" event for the "NotifyIcon", this is because it gives the option to re-launch the application whenever we double-click on the Application Icon in the Taskbar Notification Area.

Add the following line of code for this event:

void notifyIcon1_DoubleClick(object sender, EventArgs e)

{

    //Showing the original window when the Application Icon   

   // In Notification Tray is Double Clicked

    this.Show();   

  //Hiding the Application from Notification Tray

  notifyIcon1.Visible = false;

}

Step 6: Now it's time to add code for the "Exit" Context Menu that we have added earlier in our project, add the following line of codes for this:

private void exitToolStripMenuItem_Click(object sender, EventArgs e)

{

    //Exiting The Application

     Application.Exit();

}

Step 7: Now compile and run your code, when you click the button "Notify" you will see that your application will be hidden and a Balloon Pop-up will be shown on the Taskbar Notification Area of your system and your application is in the Taskbar Notification Area.

tray

That's all for this article. I am attacing the source file so you can go through it.

Up Next
    Ebook Download
    View all
    Learn
    View all