Delphi/Lazarus: Retrieve Cursor Position relative to Form/Window
Tip by Delphian | Last update on 2023-11-24 | Created on 2013-04-03
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
Android Splash Screen Tutorial
Tutorial | 0 Comments
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi: Event Order of a Form - From OnCreate to OnDestroy
Info | 1 Comment
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
How to resize Image before Upload in Browser
Tutorial | 13 Comments
Send HTML5 Canvas as Image to Server
Tutorial | 0 Comments
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.