Search code examples
c#winformssizedesign-time

How to make a form's size to fill all screen at design time?


How can I make a form fill all the screen (in terms of size) when clicked (not fullscreen like f11). At design - time (Not on code behind)?


Solution

  • At design time: use the WindowsState property defined to Maximized.

    At runtime without using this property: you can use this:

    static public class FormHelper
    {
      static public void SetSizeToScreen(this Form form)
      {
        int left = Screen.PrimaryScreen.Bounds.Left;
        int top = Screen.PrimaryScreen.Bounds.Top;
        int width = Screen.PrimaryScreen.Bounds.Width;
        int height = Screen.PrimaryScreen.Bounds.Height;
        form.Location = new Point(left, top);
        form.Size = new Size(width, height);
      }
    
      static public void SetSizeToDesktop(this Form form)
      {
        int left = SystemInformation.WorkingArea.Left;
        int top = SystemInformation.WorkingArea.Top;
        int width = SystemInformation.WorkingArea.Width;
        int height = SystemInformation.WorkingArea.Height;
        form.Location = new Point(left, top);
        form.Size = new Size(width, height);
      }
    }
    

    Usage:

    this.SetSizeToDesktop();