44 Votes

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):

  P: TPoint;
  Form1.Caption:=inttostr(P.X+' '+inttostr(P.Y));

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

AvatarThe author has not added a profile short description yet.
Show Profile


Related Topics

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.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.