MousePointer for Visual Basic 6.0 Users
In Visual Basic 2008, the Visual Basic 6.0 MousePointer property has been replaced by the Cursor property and the names of the MousePointer constants have changed.
Conceptual Differences
In Visual Basic 6.0, the MousePointer property of a form or control is used to change the appearance of the cursor when it passes over that form or control.
In Visual Basic 2008, the Cursor property provides the same functionality as the MousePointer.
Custom MousePointers
In Visual Basic 6.0, you can use any icon (.ico) or cursor (.cur) file as a custom MousePointer.
In Visual Basic 2008, only cursor files are supported; you can set a custom cursor at run time by assigning a cursor file to the Cursor property.
vbIconPointer Constant
Visual Basic 6.0 includes the MousePointer constant vbIconPointer to change the cursor to an icon symbol (a small square within a square). This constant is provided for legacy purposes only; on newer operating systems it has no effect and the default cursor is displayed. There is no equivalent in Visual Basic 2008.
Code Changes for the MousePointer Property
The following examples illustrate the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Changing the Cursor Appearance
The following code demonstrates how the cursor changes appearance when it passes over a text box control at run time, replacing the default arrow with an hourglass cursor. The Visual Basic 6.0 example sets the MousePointer property; in the Visual Basic 2008 example, the Cursor property is the equivalent of MousePointer. The Visual Basic 2008 example also uses the new MouseEnter event.
' Visual Basic 6.0
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Text1.MousePointer = vbHourGlass
End Sub
' Visual BasicPrivateSub TextBox1_MouseEnter(ByVal sender AsObject, _
ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
TextBox1.Cursor = System.Windows.Forms.Cursors.WaitCursor
EndSub
Displaying a Custom Cursor
The following code demonstrates the display of a hand cursor when the cursor passes over a text box control. The Visual Basic 6.0 example sets both the MouseIcon and MousePointer properties; the Visual Basic 2005 example sets the Cursor property to a new instance of a Cursor object.
' Visual Basic 6.0
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Text1.MouseIcon = LoadPicture("C:\Windows\Cursors\hmove.cur")
Text1.MousePointer = vbHourGlass
End Sub
' Visual BasicPrivateSub TextBox2_MouseEnter(ByVal sender AsObject, _
ByVal e As System.EventArgs) Handles TextBox2.MouseEnter
TextBox2.Cursor = New System.Windows.Forms.Cursor _
("C:\mypath\mycursor.cur")
EndSub
MousePointer Constant Equivalencies
The following table lists Visual Basic 6.0 constants and their Visual Basic 2008 equivalents.
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
0 – vbDefault |
|
1 – vbArrow |
|
2 – vbCrossHair |
|
3 – vbIBeam |
|
4 – vbIconPointer |
Obsolete — replaced by Default |
5 – vbSizePointer |
|
6 – vbSizeNESW |
|
7 – vbSizeNS |
|
8 – vbSizeNWSE |
|
9 – vbSizeWE |
|
10 – vbUpArrow |
|
11 – vbHourGlass |
|
12 – vbNoDrop |
|
13 – vbArrowHourGlass |
|
14 – vbArrowQuestion |
|
15 – vbSizeAll |
|
99 – vbCustom |
No equivalent — for more information, see Cannot set a custom MousePointer |
Upgrade Notes
When a Visual Basic 6.0 application is upgraded to Visual Basic 2008, the MousePointer property is replaced by the Cursor property. Code that uses MousePointer constants is modified to use Visual Basic 2008 Cursors enumerations.
If the Visual Basic 6.0 application uses a custom MousePointer, the design-time setting or custom MousePointer code will not be upgraded and a warning will be issued.
In addition, if the Visual Basic 6.0 application sets the MousePointer to the vbIconPointer constant at either design time or run time, it will be replaced by the default cursor during upgrade.
See Also
Reference
Cannot set a custom MousePointer
Other Resources
Windows Forms Controls for Visual Basic 6.0 Users
Control Property, Method, and Event Changes for Visual Basic 6.0 Users