MouseDown, MouseUp Events

Purpose

Occur when the user presses (MouseDown) or releases (MouseUp) a mouse button.

Syntax

Sub Object_MouseDown([index%,] button&, shift&, x!, y!)

Sub Object_MouseUp([index%,] button&, shift&, x!, y!)

Object: Ocx Object
button&, shift&: Short integer exp
x!, y!: Single exp

Description

ObjectReturns an Ocx object expression.

index% Returns an integer that uniquely identifies a form or control if it's in a form or control array.
button& Returns an integer that identifies the button that was pressed (MouseDown) or released (MouseUp) to cause the event. The button argument is a bit field with bits corresponding to the left button (bit 0), right button (bit 1), and middle button (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Only one of the bits is set, indicating the button that caused the event.
shift& Returns an integer that corresponds to the state of the SHIFT, CTRL, and ALT keys when the button specified in the button argument is pressed or released. A bit is set if the key is down. The shift argument is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2). These bits correspond to the values 1, 2, and 4, respectively. The shift argument indicates the state of these keys. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT were pressed, the value of shift would be 6.
x!, y! Returns a number that specifies the current location of the mouse pointer. The x and y values are always expressed in terms of the coordinate system set by the ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop properties of the object.

Use a MouseDown or MouseUp event procedure to specify actions that will occur when a given mouse button is pressed or released. Unlike the Click and DblClick events, MouseDown and MouseUp events enable you to distinguish between the left, right, and middle mouse buttons. You can also write code for mouse-keyboard combinations that use the SHIFT, CTRL, and ALT keyboard modifiers.

Ocx controls that are aligned at the border of the parent form (using Align) change the Scale settings of the parent. ScaleLeft and ScaleTop are set to the top-left pixel of the uncovered client area of the form. ScaleWidth and ScaleHeight are set to width and height of the uncovered area. The mouse coordinates returned from MouseX, MouseY and that are passed in the forms MouseMove, MouseUp, and MouseDown events are relative to the new origin.

Example

OpenW # 1 : FontName = "courier new"

Do

Sleep

Until Win_1 Is Nothing

 

Sub Win_1_MouseDown(Button&, Shift&, x!, y!)

Print AT(1, 1); "Mouse Down"

EndSub

 

Sub Win_1_MouseUp(Button&, Shift&, x!, y!)

Print AT(1, 1); Space(10)

EndSub

Remarks

The following applies to both Click and DblClick events:

See Also

Form, Click, DblClick, MouseMove

{Created by Sjouke Hamstra; Last updated: 02/03/2018 by James Gaite}