What's in a Mouse Event
Go Up to Responding to the Mouse
A mouse event occurs when a user moves the mouse in the user interface of an application. The VCL has three mouse events.
Mouse events :
Event | Description |
---|---|
Occurs when the user presses a mouse button with the mouse pointer over a control. | |
Occurs when the user moves the mouse while the mouse pointer is over a control. | |
Occurs when the user releases a mouse button that was pressed with the mouse pointer over a component. |
When an application detects a mouse action, it calls whatever event handler you've defined for the corresponding event, passing five parameters. Use the information in those parameters to customize your responses to the events. The five parameters are as follows:
Mouse-event parameters :
Parameter | Meaning |
---|---|
Sender |
The object that detected the mouse action |
Button |
Indicates which mouse button was involved: mbLeft, mbMiddle, or mbRight |
Shift |
Indicates the state of the Alt, Ctrl, and Shift keys at the time of the mouse action |
X, Y |
The coordinates where the event occurred |
Most of the time, you need the coordinates returned in a mouse-event handler, but sometimes you also need to check Button to determine which mouse button caused the event.
Note: Delphi uses the same criteria as Microsoft Windows in determining which mouse button has been pressed. Thus, if you have switched the default "primary" and "secondary" mouse buttons (so that the right mouse button is now the primary button), clicking the primary (right) button will record mbLeft as the value of the Button parameter.