24

So I am making a game on Visual Studio C# and I want the form to be automatically maximized to any user's computer screen when compiled? How can I do that?

John Saunders
  • 160,644
  • 26
  • 247
  • 397

7 Answers7

38

You can do it using one of the following --

  1. Set the form WindowState = FormWindowState.Maximized;
  2. Get the screen resolution using following code and set the size of your forms accordingly

    int height = Screen.PrimaryScreen.Bounds.Height; 
    int width = Screen.PrimaryScreen.Bounds.Width;
    
NickC
  • 42
  • 10
Ram
  • 11,404
  • 15
  • 62
  • 93
  • 4
    WindowState = FormWindowState.Maximized; // not WindowState=Maximized; as for PrimaryScreen work alwyas only if one display or all other display do not have smaller size – gg89 Oct 17 '15 at 18:28
  • You don't need to set Width and Height if state is Maximized. That does it alone – Fandango68 Sep 12 '22 at 05:46
23

Set the WindowState property of your form to Maximized.

That will cause your form to be maximumized when it's opened.

Jay Riggs
  • 53,046
  • 9
  • 139
  • 151
  • 1
    In addition, the [FormBorderStyle](http://msdn.microsoft.com/en-us/library/hw8kes41.aspx) can be set to `FormBorderStyle.None` to remove the border as well, for a more *true maximized feeling, no borders added*. – Patrick Jun 02 '10 at 11:14
15

You can use this.WindowState = FormWindowState.Maximized;

SchmitzIT
  • 9,227
  • 9
  • 65
  • 92
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
7
  1. Go To Load Form As View Code and use This Code :

C#:

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

VB:

Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
whoan
  • 8,143
  • 4
  • 39
  • 48
Prof Shafiei
  • 71
  • 1
  • 2
1

If you are looking for something that will maximize your window on a first click and normalizes your window on a second click, this will help.

private void maximiseButton_Click(object sender, EventArgs e)
    {

        //normalises window
        if (this.WindowState == FormWindowState.Maximized)
        {
            this.WindowState = FormWindowState.Normal;
            this.CenterToScreen();
        }

        //maximises window
        else
        {
            this.WindowState = FormWindowState.Maximized;
            this.CenterToScreen();
        }
    }
0

correct in VS2010:

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

Ahmad
  • 12,336
  • 6
  • 48
  • 88
danphm
  • 9
  • 1
0

On the Form Move Event add this:

    private void Frm_Move (object sender, EventArgs e)
    {
        Top = 0; Left = 0;
        Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    }
Segan
  • 486
  • 5
  • 5