The NotifyIcon
In past programming frameworks, it's been difficult to use a system tray icon. In .NET it's as easy as adding a simple NotifyIcon control.
Note
Like almost all invisible controls, the NotifyIcon doesn't inherit from the Control class. In other words, the list of members in Table 6-14 is essentially all you have to work with.
Table 6-14: NotifyIcon Members
MemberDescription
ContextMenuThe ContextMenu linked the system tray. It is displayed automatically when the user right-clicks the icon.
IconThe graphical icon that appears in the system tray (as an Icon object).
TextThe tooltip text that appears above the system tray icon.
VisibleSet this to true to show the icon. It defaults to false, giving you a chance to set up the rest of the required functionality.
Click, DoubleClick,
MouseDown,
MouseMove,
and MouseUp eventsThese events work the same as the Control class events with the same name. They allow you to respond to the mouse actions.
The NotifyIcon is an invisible control that appears in the component tray when added at design time. In many cases, it's more useful to create the NotifyIcon dynamically at runtime. For example, you might create a utility application that loads into the system tray and waits quietly, monitoring for some system event or waiting for user actions. In this case, you need to be able to create the system tray icon without displaying a form. A complete example of this technique is shown in Chapter 11.