How to get form coordinates? Buttons in this form? Relative to the main screen

  • one
    Check on what you have made the interface? - Kromster
  • Yesterday I realized that the program would have to be done on wpf, it would be too expensive in terms of resources in terms of effects - Fangog

3 answers 3

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.Top is for what type of this ? - 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);