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 in the system tray. You can then hook your custom C# code up to it.
Add the NotifyIcon
control by double-clicking on NotifyIcon
in the Toolbox in Visual Studio. Right click on the notifyIcon1
icon and select Properties.
MouseDoubleClick
event handler, and set some properties such as BalloonTipText
and Text.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; } } }
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.
BalloonTipIcon
property gives you the ability to render an icon on the balloon.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.
For programs that require ongoing notifications, NotifyIcon
can help integrate into the operating system with this functionality.