* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
4.2 KiB
title, ms.date, dev_langs, f1_keywords, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Add Application Icons to the TaskBar with NotifyIcon Component | 03/30/2017 |
|
|
|
d28c0fe6-aaf2-4df7-ad74-928d861a8510 |
How to: Add Application Icons to the TaskBar with the Windows Forms NotifyIcon Component
The Windows Forms xref:System.Windows.Forms.NotifyIcon component displays a single icon in the status notification area of the taskbar. To display multiple icons in the status area, you must have multiple xref:System.Windows.Forms.NotifyIcon components on your form. To set the icon displayed for a control, use the xref:System.Windows.Forms.NotifyIcon.Icon%2A property. You can also write code in the xref:System.Windows.Forms.NotifyIcon.DoubleClick event handler so that something happens when the user double-clicks the icon. For example, you could make a dialog box appear for the user to configure the background process represented by the icon.
Note
The xref:System.Windows.Forms.NotifyIcon component is used for notification purposes only, to alert users that an action or event has occurred or there has been a change in status of some sort. You should use menus, toolbars, and other user-interface elements for standard interaction with applications.
To set the icon
-
Assign a value to the xref:System.Windows.Forms.NotifyIcon.Icon%2A property. The value must be of type
System.Drawing.Iconand can be loaded from an .ico file. You can specify the icon file in code or by clicking the ellipsis button (
) next to the xref:System.Windows.Forms.NotifyIcon.Icon%2A property in the Properties window, and then selecting the file in the Open dialog box that appears. -
Set the xref:System.Windows.Forms.NotifyIcon.Visible%2A property to
true. -
Set the xref:System.Windows.Forms.NotifyIcon.Text%2A property to an appropriate ToolTip string.
In the following code example, the path set for the location of the icon is the My Documents folder. This location is used because you can assume that most computers running the Windows operating system will include this folder. Choosing this location also enables users with minimal system access levels to safely run the application. The following example requires a form with a xref:System.Windows.Forms.NotifyIcon control already added. It also requires an icon file named
Icon.ico.' You should replace the bold icon in the sample below ' with an icon of your own choosing. NotifyIcon1.Icon = New _ System.Drawing.Icon(System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ & "\Icon.ico") NotifyIcon1.Visible = True NotifyIcon1.Text = "Antivirus program"// You should replace the bold icon in the sample below // with an icon of your own choosing. // Note the escape character used (@) when specifying the path. notifyIcon1.Icon = new System.Drawing.Icon (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + @"\Icon.ico"); notifyIcon1.Visible = true; notifyIcon1.Text = "Antivirus program";// You should replace the bold icon in the sample below // with an icon of your own choosing. notifyIcon1->Icon = gcnew System::Drawing::Icon(String::Concat (System::Environment::GetFolderPath (System::Environment::SpecialFolder::Personal), "\\Icon.ico")); notifyIcon1->Visible = true; notifyIcon1->Text = "Antivirus program";