0% found this document useful (0 votes)
37 views4 pages

MouseMove Event - Microsoft Docs

The MouseMove event occurs when the user moves the mouse over an object. It provides information about the mouse position and button/key states. The event syntax varies slightly depending on the control but includes details like the button pressed and shift key states. MouseMove events are generated continuously as the mouse moves and can cascade if moving a form underneath the pointer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

MouseMove Event - Microsoft Docs

The MouseMove event occurs when the user moves the mouse over an object. It provides information about the mouse position and button/key states. The event syntax varies slightly depending on the control but includes details like the button pressed and shift key states. MouseMove events are generated continuously as the mouse moves and can cascade if moving a form underneath the pointer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MouseMove event | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/language/reference/user-inter...

MouseMove event
11/15/2018 • 2 minutes to read •
In this article
Syntax
Settings
Remarks
See also

Occurs when the user moves the mouse.

Syntax
For MultiPage, TabStrip
Private Subobject _MouseMove(indexAs Long,
ByValButtonAs fmButton,
ByValShiftAs fmShiftState,
ByValXAs Single,
ByValYAs Single)

For other controls


Private Subobject _MouseMove( ByValButtonAs fmButton,
ByValShiftAs fmShiftState,
ByValXAs Single,
ByValYAs Single)

The MouseMove event syntax has these parts:

Part Description

object Required. A valid object name.

index Required. The index of the page or tab in a MultiPage or TabStrip associated with
this event.

Button Required. An integer value that identifies the state of the mouse buttons.

1 of 4 11/9/2020, 12:54 PM
MouseMove event | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/language/reference/user-inter...

Part Description

Shift Required. Specifies the state of SHIFT, CTRL, and ALT.

X, Y Required. The horizontal or vertical position, measured in points, from the left or
top edge of the control.

Settings
The index argument specifies which page or tab was clicked over. A - 1 designates that
the user did not click any of the pages or tabs.

The settings for Button are:

Value Description

0 No button is pressed.

1 The left button is pressed.

2 The right button is pressed.

3 The right and left buttons are pressed.

4 The middle button is pressed.

5 The middle and left buttons are pressed.

6 The middle and right buttons are pressed.

7 All three buttons are pressed.

The settings for Shift are:

Value Description

1 SHIFT was pressed.

2 CTRL was pressed.

2 of 4 11/9/2020, 12:54 PM
MouseMove event | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/language/reference/user-inter...

Value Description

3 SHIFT and CTRL were pressed.

4 ALT was pressed.

5 ALT and SHIFT were pressed.

6 ALT and CTRL were pressed.

7 ALT, SHIFT, and CTRL were pressed.

You can identify individual keyboard modifiers by using the following constants:

Constant Value Description

fmShiftMask 1 Mask to detect SHIFT.

fmCtrlMask 2 Mask to detect CTRL.

fmAltMask 4 Mask to detect ALT.

Remarks
The MouseMove event applies to forms, controls on a form, and labels.

MouseMove events are generated continually as the mouse pointer moves across
objects. Unless another object has captured the mouse, an object recognizes a
MouseMove event whenever the mouse position is within its borders.

Moving a form can also generate a MouseMove event even if the mouse is stationary.
MouseMove events are generated when the form moves underneath the pointer. If a
macro or event procedure moves a form in response to a MouseMove event, the event
can continually generate (cascade) MouseMove events.

If two controls are very close together, and you move the mouse pointer quickly over
the space between them, the MouseMove event might not occur for that space. In such
cases, you might need to respond to the MouseMove event in both controls.

3 of 4 11/9/2020, 12:54 PM
MouseMove event | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/language/reference/user-inter...

You can use the value returned in the Button argument to identify the state of the
mouse buttons.

Use the Shift argument to identify the state of SHIFT, CTRL, and ALT when the
MouseMove event occurred. For example, if both CTRL and ALT are pressed, the value of
Shift is 6.

Note

You can use MouseDown and MouseUp event procedures to respond to events
caused by pressing and releasing mouse buttons.

See also
Microsoft Forms examples
Microsoft Forms reference
Microsoft Forms concepts

Support and feedback


Have questions or feedback about Office VBA or this documentation? Please see Office
VBA support and feedback for guidance about the ways you can receive support and
provide feedback.

Is this page helpful?

Yes No

4 of 4 11/9/2020, 12:54 PM

You might also like