Good day to all. I encountered such a problem: when resizing the form, it goes beyond the screen (Left and lower border). So how can you control it and if the form goes beyond the left border then move it to the right and if the form goes beyond the bottom then move it up. For a more detailed description of the problem you can watch the video: Click here.

  • How to be in a situation where the form is larger than the screen? - Andrei NOP
  • Not quite. On the video you can see that the form can be moved to the left when it crosses the right border. Here's how to control this? - Berianidze Luka

1 answer 1

Use Screen.PrimaryScreen.WorkingArea to determine screen sizes.

In the subscriber not the Form_Resize event write:

 if (Right > Screen.PrimaryScreen.WorkingArea.Width) Left = Screen.PrimaryScreen.WorkingArea.Width - Width; 
  • That is, if if (Left + Width> Screen.PrimareScreen.WorkingArea.Width) .... change location ....? Do you understand correctly? - Berianidze Luka
  • Like that. You tried? - Andrei NOP
  • I tried var sc = Screen.GetBounds (this); if (this.Right> sc.Width) {Rectangle r = Screen.FromControl (this) .WorkingArea; this.Location = new Point (this.Right - sc.Width, this.Location.Y); } - Berianidze Luka
  • But at the same time the form lags terribly. - Berianidze Luka
  • It should look something like this youtu.be/M8n-DRmZLqkhd = 1 - Berianidze Luka