Notice that all the graphics methods can use a Color argument. If that argument is omitted, the ForeColor property is used.Color is actually a hexadecimal (long integer) representation of color - look in the Properties Window at some of the values of color for various object properties. So, one way to get color values is to cut and paste values from the Properties Window. There are other ways, though.
Visual Basic offers eight symbolic constantsto represent some basic colors. Any of these constants can be used as a Color argument.
For Microsoft QBasic, GW-Basic and QuickBasic programmers, Visual Basic replicates the sixteen most used colors with the QBColor function. The color is specified byQBColor(Index), where the colors corresponding to the Index are:
|7||White||7||Light (bright) white|
The RGB function can be used to produce oneof 224 (over 16 million) colors! The syntax for using RGB to specify the color property is:
RGB (Red, Green, Blue)
where Red, Green, and Blue are integer measures of intensity of the corresponding primary colors.These measures can range from 0 (leastintensity) to 255 (greatest intensity). For example, RGB(255, 255, 0) will produce yellow.
Any of these fourrepresentations of color can be used anytime your Visual Basic code requires acolor value.
Example.ForeColor= RGB(100, 100, 100)
Related to graphics methods are mouse events. The mouse is a primary interface to performing graphics in Visual Basic. We've already used the mouse to Click and DblClick on objects.Here, we see how to recognize other mouse events to allow drawing in forms and picture boxes.
The MouseDown event procedure is triggered whenever a mouse button is pressed while the mouse cursor is over anobject.The form of this procedure is:
SubObjectName_MouseDown(Button As Integer, Shift As Integer, X As Single, Y AsSingle).End Sub
The Arguments are -
Button Specifies which mouse button was pressed.
Shift Specifies state of Shift, Ctrl, and Alt keys.
X, Y Coordinate of mouse cursor when button was pressed.
Values for theButton argument are -
|vbLeftButton||1||Left button is pressed.|
|vbRightButton||2||Right button is pressed.|
|vbMiddleButton||4||Middle button is pressed.|
Only one button press can be detected by the MouseDown event.
Values for the Shift argument are -
|vbShiftMask||1||Shift key is pressed.|
|vbCtrlMask||2||Ctrl key is pressed.|
|vbAltMask||4||Alt key is pressed.|
The Shift argument can represent multiple key presses.
For example, if Shift = 5 (vbShiftMask +vbAltMask),
both the Shift and Alt keys are being pressed when the MouseDownevent occurs.
The MouseUp event is the opposite of theMouseDown event.It is triggeredwhenever a previously pressed mouse button is released.The procedure outline is:
SubObjectName_MouseUp(Button As Integer, Shift As Integer, X As Single, Y AsSingle)
The arguments are -
Button Specifies which mouse button was released.
Shift Specifiesstate of Shift, Ctrl, and Alt keys.
X, Y Coordinate of mouse cursor when button was released.
The Button and Shift constants are the same as those for the MouseDown event.
The MouseMove event is continuouslytriggered whenever the mouse is being moved. The procedure outline is:
SubObjectName_MouseMove(Button As Integer, Shift As Integer, X As Single, Y AsSingle)
The arguments are -
Button Specifies which mouse button(s), if any, are pressed.
Shift Specifies state of Shift, Ctrl, and Alt keys
X, YCurrent coordinate of mouse cursor
The Button and Shift constants are the same as those for the MouseDown event.A difference here is that the Button argumentcan also represent multiple button presses or no press at all.For example, if Button = 0, no button ispressed as the mouse is moved.If Button= 3 (vbLeftButton + vbRightButton), both the left and right buttons are pressedwhile the mouse is being moved.
Related Online Articles:
No comment yet. Be the first to post a comment.