Let's say I have a Control and its location is relative to its parent. If its embedded many times and is the great great great grandchild of the main form, how can I determine what its location is on my entire screen, not just its location in the immediate parent? This is for the purpose of printing a particular Control via a screenshot (since for some controls the DrawToBitmap doesn't work properly).
You're looking for the PointToScreen
method:
Point location = someControl.PointToScreen(Point.Empty);
-
3Note that PointToScreen takes client area coordinates, so using this code on a Form for instance would not give the correct result. – rymdsmurf Feb 18 '15 at 10:49
-
4@rymdsmurf not sure if I understand you correctly, but if you use it on a
Form
(likemyForm.PointToScreen
) and you have the right coordinates (fromcontrol.Location
) it will give you the right coordinates on the screen. – Artholl May 4 '15 at 8:06 -
2As a note: make sure your screens are scaled to 100% to get correct values. Mine was 125% and I was getting wrong values. – Bitterblue May 30 '18 at 7:26
-
1
-
2@pookie you can get a Graphics object (Dim g As Graphics = CreateGraphics()) and use (g.DpiX / 96) to get the scaling factor. It ill be 1 for 100% and 1.5 for 150%. – Richard Moore Nov 7 '18 at 16:34