VCL.TMouseEvent (Delphi)
Description
This example shows how to use the TMouseEvent function type.
To build and test this example, create a VCL Forms Application - Delphi, and add the following on the form:
- Two TButton objects that trigger the Vcl.Controls.TMouseEvent.
Code
Before writing the code, add a Vcl.Controls.TControl.OnMouseDown event handler for the first button and a Vcl.Controls.TControl.OnMouseUp event handler for the second button.
var
Form1: TForm1;
aPoint: TPoint;
globalScreenPoint: TPoint;
// This procedure lists the coordinates of the mouse position reported to the screen.
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
aPoint.Create(X,Y); //Takes the coordinates of the mouse current position
globalScreenPoint := ClientToScreen(aPoint); //Translates the given coordinates to global screen coordinates
ShowMessage(IntToStr(globalScreenPoint.X)+' '+IntToStr(globalScreenPoint.Y));
end;
// This procedure lists the coordinates of the mouse position reported to the sender object (Button2, in this case).
procedure TForm1.Button2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ShowMessage(IntToStr(X)+' '+IntToStr(Y));
end;