Icons


Each form in a Visual Basic application has its own icon. A form’s icon is displayed on the left side of its title bar, in the system’s taskbar, and by applications such as the Task Manager and Windows Explorer.

Some of these applications display icons at different sizes. For example, if you set Windows Explorer’s view to Large Icons, it displays 32 × 32 pixel icons. Windows Explorer displays 16 × 16 pixel icons for its other views.

If an icon file doesn’t provide whatever size Windows needs, the system shrinks or enlarges an existing image to fit. That may produce an ugly result. To get the best appearance, you should ensure that icon files include at least 16 × 16 and 32 × 32 pixel sizes. Depending on the characteristics of your system, you may also want to include other sizes.

The integrated Visual Studio icon editor enables you to define images for various color models ranging from monochrome to 256 colors, and sizes ranging from 16 × 16 to 96 × 96 pixels. It even lets you build icon images with custom sizes such as 32 × 48 pixels, although it is unlikely that Windows will need to use those.

To use this editor, open Solution Explorer and double-click the My Project entry to open the project properties window. Select the Resources tab, open the Add drop-down, and select New Icon. Use the drawing tools to build the icons. Right-click the icon and use the Current Icon Image Types submenu to work with icons of different sizes.

To assign an icon to a form at design time, open the Form Designer and select the Icon property in the Properties window. Click the ellipsis button on the right and select the icon file that you want to use.

To assign an icon to a form at runtime, set the form’s Icon property to an Icon object. The following code sets the form’s Icon property to an icon resource named MainFormIcon.

  Me.Icon = My.Resources.MainFormIcon 

Some applications change their icons to provide an indication of their status. For example, a process-monitoring program might turn its icon red when it detects an error. It could even switch back and forth between two icons to make the icon blink in the taskbar.

Application Icons

Windows displays a form’s icon in the form’s title bar, in the taskbar, and in the Task Manager. Applications (such as Windows Explorer) that look at the application as a whole rather than at its individual forms display an icon assigned to the application, not to a particular form. To set the application’s icon, open Solution Explorer and double-click the My Project entry to open the Project Properties window. In the Icon drop-down list, select the icon file that you want to use or select <Browse...> to look for the file you want to use.

Note that these different purposes display icons at different sizes. For example, the icon in the form’s title bar is very small, while the one displayed by Task Manager is relatively large. As the previous section mentions, the integrated Visual Studio icon editor enables you to define images for various color models and sizes in the same icon file.

Notification Icons

Visual Basic applications can display one other kind of icon by using the NotifyIcon control. This control can display an icon in the system tray. The system tray (also called the status area) is the little area holding small icons that is usually placed in the lower-left part of the taskbar, and shown in Figure 10-6. The little stop light in the upper left is an icon displayed by a NotifyIcon control. Hovering the mouse over the icon makes it display a tooltip showing its text, in this case Stopped.

image from book
Figure 10-6: An application can use a NotifyIcon control to display status icons in the system tray.

The control’s Icon property determines the icon that it displays. A typical application will change this icon to give information about the program’s status. For example, a program that monitors the system’s load could use its system tray icon to give the user an idea of the current load. Notification icons are particularly useful for programs that have no user interface or that run in the background so that the user isn’t usually looking at the program’s forms.

Notification icons also often include a context menu that appears when the user right-clicks on the icon. The items in the menu enable the user to control the application. If the program has no other visible interface, this may be the only way the user can control it.

Appendix G describes the NotifyIcon control in greater detail.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net