user3003149
user3003149

Reputation:

How to get exact position of a panel or picturebox?

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

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236188

Use Control.PointToScreen Method to get location relative to screen:

Point location = PointToScreen(panel.Location);

Upvotes: 3

Related Questions