Home
Map
NotifyIconUse the NotifyIcon control in Windows Forms to create notification messages.
WinForms
This page was last reviewed on Oct 5, 2022.
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.
Detail 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.
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; } } }
Icon. How can you change the icon? Go into Properties and then click on the Icon entry. You need to use an ICO file. You can make an ICO with favicon converters on the Internet.
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.
Text
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 tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Oct 5, 2022 (edit).
Home
Changes
© 2007-2024 Sam Allen.