NotifyIcon. A notification icon notifies the user. In Windows there is a Notification Icons section—typically in the bottom right corner.
Control notes. With the NotifyIcon control in Windows Forms, you can add an icon of your own in the system tray. You can then hook your custom C# code up to it.
Example. Add the NotifyIcon control by double-clicking on NotifyIcon 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.
Info This example uses the Load event to show a balloon tip. When the program starts up, the balloon will show.
Note Balloons are prominent notifications but don't interrupt the workflow of the user as much as dialogs.
Detail When you double-click on the logo in the bottom right, you will get a dialog box.
Tip To change the icon, go into Properties and then click on the Icon entry. You need to use an ICO file.
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;
}
}
}
Balloons. 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.
Also The BalloonTipIcon property gives you the ability to render an icon on the balloon.
Text. The Text property on NotifyIcon is rendered as a tooltip. When you hover the mouse over the icon, the string from the Text property will appear.
A summary. For programs that require ongoing notifications, NotifyIcon can help integrate into the operating system with this functionality.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Dec 24, 2024 (simplify).