Can I calculate the location of a widget relative to the form on which it lies?

S

steve bull

I have a picture box which lies on a panel which lies on a form. Is there some way that I can calculate the position of
the picture box relative to the form rather than the panel on which it lies? The location of the picture box in the
Control class is given relative to the panel on which it lies.


Thanks,

Steve
 
T

Tim Wilson

There might be a better way to do this, but one way is to convert the child
controls location into screen coordinates and then convert that point back
to client coordinates using the Form. Something like the code below, where
"this" is a reference to the Form.

Point p =
this.PointToClient(this.panel1.PointToScreen(this.pictureBox1.Location));

--
Tim Wilson
..Net Compact Framework MVP

steve bull said:
I have a picture box which lies on a panel which lies on a form. Is there
some way that I can calculate the position of
the picture box relative to the form rather than the panel on which it
lies? The location of the picture box in the
 

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