Place a notify icon in the system taskbar in C#

The NotifyIcon control makes this relatively easy. First place the control on your form.

At run time, set the NotifyIcon control's Icon property to determine what image it displays in the taskbar. You can also set its Text property to determine the text it displays when the user hovers over it.

This example displays two radio buttons that display happy and sad pictures. When you click one, the program displays the corresponding icon on the form and on its NotifyIcon.

The program also gives its NotifyIcon a context menu. At run time you can right-click on the NotifyIcon to open the menu and select either Happy or Sad commands.

To save code, the code uses the same event handlers for the radio buttons' and menu items' Click events.

The following code shows how this example works.

// Display the happy icon.
private void radHappy_Click(object sender, EventArgs e)
{
this.Icon = Properties.Resources.Happy;
NotifyIcon1.Icon = Properties.Resources.Happy;
NotifyIcon1.Text = "Happy";
}

// Display the sad icon.
private void radSad_Click(object sender, EventArgs e)
{
this.Icon = Properties.Resources.Sad;
NotifyIcon1.Icon = Properties.Resources.Sad;
NotifyIcon1.Text = "Sad";
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.