Page 59 - Open Soource Technologies 304.indd
P. 59
Unit 3: Understanding Controls and Control Events
Mouse Down, MouseUp
Button As Integer, Shift As Integer, X As Single, Y As Single
This event occurs when a mouse button is pressed down or released over a Command Button.
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Button = vbMiddleButton Then
MsgBox “The middle button was pressed on the Command Button”
End If
End Sub
The Button argument returns one of the following possible values:
Constant Value Description
vbLeftButton 1 Left mouse button
vbRightButton 2 Right mouse button
vbMiddleButton 4 Middle mouse button
The Shift argument works the in same the same way as in the KeyDown and KeyUp events. The
X and Y arguments return the position of the cursor in relation to the Command Button i.e., the
coordinates of the very top-left of the Command Button are 0, 0.
The MouseDown event occurs before the Click event and the MouseUp event occurs after the
Click event.
3.4.4.4 Other Things to Try
Colored Text
It is not possible to change the color of the text of the Command Button’s text as there is no Fore
Color property. The only way to do it is to create a picture of colored text and use it as the Picture
property. Remember to set the following properties:
• Caption: “” (no text)
• MaskColor: the background color of the picture if its not already transparent
• Picture: the picture of the colored text
• Style: 1 - Graphical
• UseMaskColor: True (if necessary)
LOVELY PROFESSIONAL UNIVERSITY 53