// Obtain the current position of the mouse in the form procedure tform1.formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); var STR: string; begin STR: = format ('% d, % d', [x, y]); showmessage (STR); end;
// Getcursorpos is used to obtain the position of the mouse relative to the screen. var PS: tpoint; STR: string; begin getcursorpos (PS); STR: = format ('% d, % d', [PS. x, PS. y]); showmessage (STR); end;
// But the screentoclient method can be used to convert var PS: tpoint; STR: string; begin getcursorpos (PS); PS: = screentoclient (PS); STR: = format ('% d, % d', [PS. x, PS. y]); showmessage (STR); end;
// Clienttoscreen Function Procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); var STR: string; PS: tpoint; begin {displays the current mouse position, which is relative to the form} STR: = format ('% d, % d', [x, y]); showmessage (STR ); {the position of the current mouse relative to the screen can be obtained through the clienttoscreen function} PS: = point (x, y); PS: = clienttoscreen (PS); STR: = format ('% d, % d', [PS. x, PS. y]); showmessage (STR); end;