How to get form coordinates? Buttons in this form? Relative to the main screen
3 answers
Form coordinates:
int windowTop = this.Top; int windowLeft = this.Left; Coordinates of any control relative to the main screen:
Point location = someControl.PointToScreen(Point.Empty); this.Topis for what type ofthis? - VladD- @VladD didn’t have a WPF tag when writing a response, so this is for Windows Forms, as indicated in the question. - Yurii Manziuk
|
For WPF:
button.PointToScreen(new Point(0, 0)); (where button is your button) gives the coordinates of the upper left corner. If you need the middle of a button, then
button.PointToScreen(new Point(button.ActualWidth, button.ActualHeight)); For a window, substitute a button instead of a button .
|
Try
FindForm().PointToScreen(Control1.Location); |