MouseDown Event

Applies To   See Also

Occurs when the user presses a mouse button.

Syntax

PROCEDURE Object.MouseDown
[LPARAMETERS nIndex, nButton, nShift, nXCoord, nYCoord]

-or-

LPARAMETERS nButton, nShift, nXCoord, nYCoord

Parameters

You must include an LPARAMETERS or PARAMETERS statement in the event procedure and specify a name for each parameter. Visual FoxPro passes the MouseDown event four of five parameters in the following order:

nIndex

Contains a number which uniquely identifies a control if it is in a control array. The nIndex parameter is passed only when the control is part of a control array.

nButton

Contains a number that specifies which button was pressed to trigger the event: 1 (left), 2 (right), or 4 (middle).

nShift

Contains a number specifying the state of modifier keys when the mouse is pressed. The valid modifier keys are the SHIFT, CTRL, and ALT keys.

The values returned in nShift for individual modifier keys are listed in the following table.

Modifier key values for nShift

Windows key Value
SHIFT 1
CTRL 2
ALT 4

If more than one modifier key is held down when the mouse is pressed, the nShift argument contains the sum of the values for the modifier keys. For example, if the user holds CTRL while pressing the mouse button, the nShift argument contains 2. But If the user holds CTRL+ALT while pressing the mouse button, the nShift argument contains 6.

nXCoord, nYCoord

Contains the current horizontal (nXCoord) and vertical (nYCoord) position of the mouse pointer within the form. These coordinates are expressed in terms of the form's coordinate system in the unit of measurement specified by the ScaleMode property of the form.

Remarks

Use a MouseDown procedure to specify actions to occur when a given mouse button is pressed. Unlike the Click and DblClick events, you can use the MouseDown event to distinguish between the left, right, and middle mouse buttons. You can also write code for mouse-keyboard combinations that use the modifier keys.

You can use a MouseMove event to respond to an event caused by moving the mouse. The nButton argument for MouseDown and MouseUp differs from the nButton argument used for MouseMove. For MouseDown or MouseUp, the nButton argument indicates exactly one button per event; for MouseMove, it indicates the current state of all buttons.