How can I get cursor position on the form?

Little Helper picture Little Helper · Apr 20, 2011 · Viewed 10.1k times · Source

I need to get cursor position on the form, how would I do that?

Answer

David Heffernan picture David Heffernan · Apr 20, 2011

Pass Mouse.CursorPos to TForm.ScreenToClient().

Mouse.CursorPos is returned in the screen coordinate system. TForm.ScreenToClient() converts points into the form's client coordinate system.

In fact all TControl descendants offer the ScreenToClient() method, and its inverse, ClientToScreen(), to convert between coordinate systems.