TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# NotifyIcon: Windows Forms

Use the NotifyIcon control in Windows Forms to create notification messages.
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. 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.

ShowBalloonTip: This example uses the Load event on the enclosing form 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.

MouseDoubleClick: 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.

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; } } }
Icon. 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.
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 in Visual Studio.

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

Text. 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. 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.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf