Reputation:
I'm creating C# application where I have a text box and a panel on the main form. I want to get the exact position of the panel relative to the screen's top-left corner (0,0). When I call this.Left
and this.Top
at the form it gives me the correct coordinates, but when I call panel.Location.X
and panel.Location.Y
it results in coordinates relative to the form, which is constant no matter where my form is located on the screen.
I want to get the top and left coordinates of a panel not relative to the form but relative to the screen, assuming top & left of the screen is (0,0).
How can I get the absolute position of my panel?
Upvotes: 0
Views: 2507
Reputation: 236188
Use Control.PointToScreen Method to get location relative to screen:
Point location = PointToScreen(panel.Location);
Upvotes: 3