37 Votes

Delphi: Retrieve X/Y Position of a Control relative to the Screen

Tip by Delphian | 2013-04-03 at 03:44

Today, I would like to show you a way of how to get the X/Y coordinates of a control relative to the screen coordinates (and not to the coordinate system of the form). 

In the example, we are retrieving the position of a TPanel named Panel1, but you can also use any other control:

var
  P: TPoint;
begin
  P:=Panel1.ClientToScreen(Point(0,0));
  Form1.Caption:=inttostr(P.X)+' '+inttostr(P.Y));
end;

This retrieves the upper left position of the Panel relative to the screen and writes the position into the caption of Form1.

ReplyPositiveNegative

About the Author

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

 

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

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.