We will have several tips in one using the Mouse Pointer.
A few days ago I was working on a project that had a company logo on the
form. Now, when you click on the logo it will take you
to the companies web site. Now that part was easy, but I was thinking,
wouldn't it be nice if when you moved the mouse pointer over
the logo you would get the hand pointer. You know, just like when the
mouse pointer moves over a live link on a web page. Well VB
doesn't have a mouseover like JavaScript but what it does have is the
MouseMove and MouseDown.
So this weeks VB Tip we will be using the mouse pointer. So
start a new project add a image control, 2 labels and a command button.
On the first label caption write "red" and the other label
caption write "blue".
Attached
to the bottom of this tip is a zip file, these are the hand pointers you will need to complete this tip. The other
image you will need
is the Element K logo. To download that just hold you mouse over the Element K logo at the top of this forum,
right click and select,
"save picture as" in IE or "save image as" in Netscape. You will add this logo to the Image1 control. Now make
sure that all the images are in the program directory.
Note: I have list all the Mouse Pointer Constant at the end
of this tip. For this tip we will be using VBHourglass(11) and
VBCustom(99)
=================================================================
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Image1.MouseIcon = LoadPicture(App.Path & "\IE5smaller.cur")
Image1.MousePointer = 99 'Allows customs icons
End Sub
Private Sub Image1_Click()
Dim sURL, openPage As String
Screen.MousePointer = vbHourglass
'open the URL using the default browser
sURL = "http://learn.elementk.com"
openPage = ShellExecute(Me.hwnd, "open", sURL, 0&, 0&, SW_SHOWNORMAL)
Screen.MousePointer = vbDefault
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Label1.ForeColor = vbRed
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Label2.ForeColor = vbBlue
End Sub
Private Sub Command1_Click()
Dim X As Long, P as Integer
'I use the MousePointer when a process may take awhile
'It lets the user know that something is happening
Screen.MousePointer = vbHourglass
For X = 1 To 20000 '1000 milliseconds = 1 second
P = DoEvents()
Next X
Screen.MousePointer = vbDefault
End Sub
====================================================
MousePointer Constant
Constant Value Description
vbDefault 0 (Default) Shape determined by the object.
VbArrow 1 Arrow.
VbCrosshair 2 Cross (crosshair pointer).
VbIbeam 3 I beam.
VbIconPointer 4 Icon (small square within a square).
VbSizePointer 5 Size (four-pointed arrow pointing north, south, east, and west).
VbSizeNESW 6 Size NE SW (double arrow pointing northeast and southwest).
VbSizeNS 7 Size N S (double arrow pointing north and south).
VbSizeNWSE 8 Size NW SE (double arrow pointing northwest and southeast).
VbSizeWE 9 Size W E (double arrow pointing west and east).
VbUpArrow 10 Up Arrow.
VbHourglass 11 Hourglass (wait).
VbNoDrop 12 No Drop.
VbArrowHourglass 13 Arrow and hourglass.
vbArrowQuestion 14 Arrow and question mark.
vbSizeAll 15 Size all.
vbCustom 99 Custom icon specified by the MouseIcon property.
Handpointers.zip