Delphi: Retrieve Cursor Position relative to Form/Window
Tip by Delphian | 2013-04-03 at 03:37
With the function GetCursorPos(), you are able to get the cursor position relative to the screen. Here is a way of how to get the position of the cursor relative to a form (window):
var P: TPoint; begin GetCursorPos(P); P:=Form1.ScreenToClient(P); Form1.Caption:=inttostr(P.X+' '+inttostr(P.Y)); end;
First, we are using GetCursorPos() to save the current mouse position to the point P. After that, we convert the screen coordinates to the form coordinates of Form1 by using ScreenToClient(). Finally, we output the converted coordinates as the caption of our window.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
Delphi: GetCursorPos problem on Windows 8.1 with scaling
Open Question | 1 Answer
Delphi/Lazarus: Get Handle of Window under Mouse Cursor
Question | 1 Answer
CSS: Reset property "position"
Question | 1 Answer
Delphi: Insert TabSheet at first position of PageControl
Question | 1 Answer
Delphi/Lazaus: Center Application Window in the middle of the Screen
Question | 1 Answer
CSS: Underline Links only when Mouse Cursor is over them
Question | 1 Answer
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.