absolute position in the screen

M

Miquel

Hi all,

Does anybody know how I can get the absolute coordenates X and Y of a
control in the screen?.

Example. I have a MainForm and inside of it there is a child Form,
which in turn has a Label inside. The Top and Left properties of this
Label return coordenates related at the begining of his parent (child
form), but I want to know this Top and Left properties from upper
left corner of the screen.

Sorry about that question, but I have spend a lot of time (10 to 12
hours) trying to figure it out. I have tried this with
'ClientToScreen' Windows API, but I couldn't solve it.

Please examples are welcome.

thanks a lot.
Miquel
 
A

Ahmed Qurashi

Use Control's PointToScreen method.

Point labelOrigin = new Point(0, 0); // this is referencing the control
Point screenOrigin = label1.PointToScreen(labelOrigin); // this references
the screen coordinate system

It works even for nested controls.

ok,
aq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top