C# NotifyIcon

NotifyIcon

A notification icon notifies the user. In Windows there is a Notification Icons section—typically in the bottom right corner. With the NotifyIcon control in Windows Forms, you can add an icon of your own there and hook C# code up to it.

Example

Steps

First, please add the NotifyIcon control to your program by double-clicking on the NotifyIcon entry in the Toolbox in Visual Studio. Right click on the notifyIcon1 icon and select Properties.

And:There you can add the MouseDoubleClick event handler, and set some properties such as BalloonTipText and Text.

Example that demonstrates NotifyIcon: C#

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
	public Form1()
	{
	    InitializeComponent();
	}

	private void Form1_Load(object sender, EventArgs e)
	{
	    // When the program begins, show the balloon on the icon for one second.
	    notifyIcon1.ShowBalloonTip(1000);
	}

	private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
	{
	    // When icon is double-clicked, show this message.
	    MessageBox.Show("Doing something important on double-click...");
	    // Then, hide the icon.
	    notifyIcon1.Visible = false;
	}
    }
}
Note

Calling ShowBalloonTip. This example uses the Load event on the enclosing form to show a balloon tip. This means that when the program starts up, the balloon will automatically show.

Note:Balloons are more prominent notifications but don't interrupt the workflow of the user as much as dialogs.

MouseDoubleClick event handler. In this program, when you double-click on the logo in the bottom right, you will get a dialog box. Then, the icon will vanish from the screen, never to be seen again.

Icon

Question

How can you change the icon? Simply go into Properties and then click on the Icon entry. You need to use an .ico file. If you do not have this kind of file format, you can make one with favicon converters on the Internet.

Tip:Search Google for "favicon generator" and then send in your PNG or GIF file.

Balloons

Method call

When the ShowBalloon method is invoked, the balloon will appear on the screen. At this time, you should have already set the BalloonTipText and BalloonTipTitle properties in Visual Studio.

Also:The BalloonTipIcon property gives you the ability to render an icon on the balloon.

Text

Property

Another useful property you can set on the NotifyIcon is the Text property. This is rendered as a tooltip. When you hover the mouse over the icon, the string from the Text property will appear.

Text

Summary

Framework: NET

For programs that require ongoing notifications, NotifyIcon can help integrate into the operating system with this functionality. By combining the NotifyIcon with the balloon, you can introduce attention-grabbing warnings or messages.


C#: Windows