Visual Basic Concepts
You can use the MousePointer and MouseIcon properties to display a custom icon, cursor, or any one of a variety of predefined mouse pointers. Changing the mouse pointer gives you a way to inform the user that long background tasks are processing, that a control or window can be resized, or that a given control doesn't support drag-and-drop, for instance. Using custom icons or mouse pointers, you can express an endless range of visual information about the state and functionality of your application.
With the MousePointer property you can select any one of sixteen predefined pointers. These pointers represent various system events and procedures. The following table describes several of these pointers and their possible uses in your application.
Mouse pointer | Constant | Description |
vbHourglass | Alerts the user to changes in the state of the program. For example, displaying an hourglass tells the user to wait. | |
vbSizePointer | Notifies the user of changes in function. For example, the double arrow sizing pointers tell users they can resize a window. | |
vbNoDrop | Warns the user an action can't be performed. For example, the no drop pointer tells users they can't drop a file at this location. |
Each pointer option is represented by an integer value setting. The default setting is 0-Default and is usually displayed as the standard Windows arrow pointer. However, this setting is controlled by the operating system and can change if the system mouse settings have been changed by the user. To control the mouse pointer in your application, you set the MousePointer property to an appropriate value.
A complete list of mouse pointers is available by selecting the MousePointer property of a control or form and scanning the pull-down settings list or by using the Object Browser and searching for MousePointerConstants.
When you set the MousePointer property for a control, the pointer appears when the mouse is over the corresponding control. When you set the MousePointer property for a form, the selected pointer appears both when the mouse is over blank areas of the form and when the mouse is over controls with the MousePointer property set to 0-Default.
At run time you can set the value of the mouse pointer either by using the integer values or the Visual Basic mouse pointer constants. For example:
Form1.MousePointer = 11 'or vbHourglass
For More Information For a complete list of mouse pointer constants, see "MousePointer Constants" in the Language Reference.
You can set the mouse pointer to display a custom icon or cursor. Using custom icons or cursors allows you to further modify the look or functionality of your application. Icons are simply .ico files, like those shipped with Visual Basic. Cursors are .cur files and, like icons, are essentially bitmaps. Cursors, however, are created specifically to show the user where actions initiated by the mouse will take place — they can represent the state of the mouse and the current input location.
Cursors also contain hot spot information. The hot spot is a pixel which tracks the location of the cursor — the x and y coordinates. Typically, the hot spot is located at the center of the cursor. Icons, when loaded into Visual Basic through the MouseIcon property, are converted to the cursor format and the hot spot is set to the center pixel. The two differ in that the hot spot location of a .cur file can be changed, whereas that of an .ico file cannot. Cursor files can be edited in Image Editor, which is available in the Windows SDK.
To use a custom icon or cursor, you set both the MousePointer and MouseIcon properties.
To use an .ico file as a mouse pointer
Form1.MouseIcon = LoadPicture("c:\Program _
Files\Microsoft Visual _
Basic\Icons\Computer\Disk04.ico")
Both properties must be set appropriately for an icon to appear as a mouse pointer. If no icon is loaded into MouseIcon when the MousePointer property is set to 99-Custom, the default mouse pointer is used. Likewise, if the MousePointer property is not set to 99-Custom, the setting of MouseIcon is ignored.
Note Visual Basic does not support animated cursor (.ani) files.
For More Information See "MouseIcon Property" and "MousePointer Property" in the Language Reference.