Absolute location of control

  • Thread starter Thread starter Jon Slaughter
  • Start date Start date
J

Jon Slaughter

Is there a way to get a controls location in screen coordinates? (not
relative to the container it is in)?

Thanks,
Jon
 
System.Windows.Forms.Control

has a function called PointToScreen(Point p), not sure whether this is
what your look for..
 
Is there a way to get a controls location in screen coordinates? (not
relative to the container it is in)?

You can use the System.Windows.Forms.Control.PointToScreen method to convert
from client coordinates to screen coordniates and the
System.Windows.Forms.Control.PointToClient to convert from screen
coordinates to client coordinates.

n!
 
Is there an easy way to work with a controls location relative to the
form that it is in instead of the container? I need to do some
calculations based on where the control in the form but I can only seem
to find properties that give the controls location w.r.t. its container
which will through off all my calculations ;/

(right now I see the only way to do is is first convert everything to
screen coordinates then from there to form coordinates ;/)

Thanks,
Jon
 
This can be done by using the System.Windows.Forms.Control.PointToScreen
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen.aspx)
method to get the absolute screen coordinate of the point relative to the
Control, and then using the System.Windows.Forms.Control.PointToClient
method
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient.aspx)
from the Form to get the screen coordinate of the point relative to the
Form.

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

What You Seek Is What You Get
 
Kevin Spencer said:
This can be done by using the System.Windows.Forms.Control.PointToScreen
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen.aspx)
method to get the absolute screen coordinate of the point relative to the
Control, and then using the System.Windows.Forms.Control.PointToClient
method
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient.aspx)
from the Form to get the screen coordinate of the point relative to the
Form.

duh ;) Shows how much I'm really thinking ;/

Thanks,
Jon
 

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

Back
Top