Mouse Events And Colors In Visual Basic 6 - Online Article

Using Colors

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.

Symbolic Constants

Visual Basic offers eight symbolic constantsto represent some basic colors. Any of these constants can be used as a Color argument.

ConstantValueColor
vbBlack0x0Black
vbRed0xFFRed
vbGreen0xFF00Green
vbYellow0xFFFFYellow
vbBlue0xFF0000Blue
vbMagenta0xFF00FFMagenta
vbCyan0xFFFF00Cyan
vbWhite0xFFFFFFWhite

QBColor Function

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:

IndexColorIndexColor
0Black0Gray
1Blue1Light blue
2Green2Light green
3Cyan3Light cyan
4Red4Light red
5Magenta5Lightmagenta
6Brown6Yellow
7White7Light (bright) white

RGB Function

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.

Color Examples

frmExample.BackColor= vbGreenpic
Example.FillColor= QBColor(3)lbl
Example.ForeColor= RGB(100, 100, 100)

MouseEvents

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.

MouseDown Event

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 -

Symbolic ConstantValueDescription
vbLeftButton1Left button is pressed.
vbRightButton2Right button is pressed.
vbMiddleButton4Middle button is pressed.
Only one button press can be detected by the MouseDown event.

Values for the Shift argument are -

Symbolic ConstantValueDescription
vbShiftMask1Shift key is pressed.
vbCtrlMask2Ctrl key is pressed.
vbAltMask4Alt 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.

MouseUp Event

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)
End Sub

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.

MouseMove 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)
End Sub

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.

About the Author:

No further information.




Comments

No comment yet. Be the first to post a comment.