MouseEnter, MouseLeave

We've been trying to simulate these two events forever. We're so glad they finally made it into the product in VFP 7. MouseEnter fires when the mouse moves into the space occupied by a control; MouseLeave fires when the mouse moves out of the control's space.

Usage

PROCEDURE oObject.MouseEnter
LPARAMETERS [ nIndex , ] nButtons, nKeys, nXCoord, nYCoord
 
PROCEDURE oObject.MouseLeave
LPARAMETERS [ nIndex , ] nButtons, nKeys, nXCoord, nYCoord

Parameter

Value

Meaning

nIndex

 

Numeric

The member of a control array that fired the event.

Omitted

The control is not in a control array.

nButtons

0

No buttons were pressed when entering or leaving the control.

1

Only the left button was pressed.

2

Only the right button was pressed.

3

Both the left and right buttons were pressed.

4

Only the middle button was pressed.

5

Both the middle and left buttons were pressed.

6

Both the middle and right buttons were pressed.

7

All three buttons were pressed. (Not an easy feat, at least not with a wheel mouse.)

nKeys

0

No modifier keys were pressed when entering or leaving the control.

1

Only the Shift key was pressed.

2

Only the Ctrl key was pressed.

3

Both the Shift and Ctrl keys were pressed.

4

Only the Alt key was pressed.

5

Both the Shift and Alt keys were pressed.

6

Both the Ctrl and Alt keys were pressed.

7

All three modified keys were pressed. (Applies only if OUTSHOW is OFF.)

nXCoord, nYCoord

Numeric

The coordinates of the mouse location in the form's ScaleMode.


A closer look at the table of parameters should make it obvious that both the nButtons and nKeys parameters are additive. Each of the buttons and each of the keys is assigned a number that's a power of two (for example, the left button is 1, the right button is 2 and the middle button is 4). While more than one button or key is used, the value passed is the sum of the assigned values. You can use BitTest() to select only those buttons or keys you're interested in.As with most of the control-related events, the first parameter is for the rare situation when you're using a control array. Don't do that.The other parameters indicate the state of affairs when the event fired: which mouse buttons, if any, were down; which of the modifier keys (Shift, Ctrl, Alt) were pressed; and the actual mouse location. Keep in mind that MouseEnter and MouseLeave fire only when you actually come into or out of a control, so the parameter values reflect the situation at that moment. Use MouseOver to see how things are throughout your passage over a control.These events belong in the same family as the "Hot Tracking" setting for SpecialEffect—they do something when the mouse moves over an object. In fact, one of the things you can do (but "can" doesn't mean "should") with these events is implement "Hot Tracking" on your own. Change SpecialEffect to 3D in MouseEnter and change it back to Plain in MouseLeave. So why are we so glad to see these events? So that we can do things as the user moves the mouse over controls, of course. The evil side of our minds thinks of things like making controls run away or making the text unreadable, but of course, we wouldn't really do that to our users. (Would we?) What we might do, though, is change MousePointer or set the VisualEffect property of a button, or something like that.

Example

PROCEDURE MouseEnter
LPARAMETERS nButton, nKeys, nXCoord, nYCoord
 
This.FontBold = .T.
RETURN
 
PROCEDURE MouseLeave
LPARAMETERS nButton, nKeys, nXCoord, nYCoord
 
This.FontBold = .F.
RETURN

See Also

BitTest(), Control Arrays, MouseDown, MousePointer, MouseUp, SpecialEffect, VisualEffect


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .