I'm searching for a property which gives me a Control's location relative to its Form's location, not to the Form's ClientRectangle's
"0,0".
Of course I can convert everything to screen coordinates, but I wonder if there's a more direct way to do this.
You need to convert to screen coordinates and then do some math.
Point controlLoc = form.PointToScreen(myControl.Location);
The form's location is already in screen coordinates.
Now:
Point relativeLoc = new Point(controlLoc.X - form.Location.X, controlLoc.Y - form.Location.Y);
That will give you the location relative to the form's upper-left corner, rather than relative to the form's client area.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With