How can you make the form maximize to any computer screen in a Windows Forms application?
Asked Answered
R

7

26

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?

Rosaline answered 2/6, 2010 at 4:45 Comment(2)
I'm sure you mean when run, not compiled.Urbas
the answer depends on what platform you are coding for. WPF? Silverlight? WinForms? etc.Workman
R
39

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;
    
Robichaux answered 2/6, 2010 at 4:50 Comment(2)
WindowState = FormWindowState.Maximized; // not WindowState=Maximized; as for PrimaryScreen work alwyas only if one display or all other display do not have smaller sizeOdaniel
You don't need to set Width and Height if state is Maximized. That does it aloneGeoffrey
T
24

Set the WindowState property of your form to Maximized.

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

Timmytimocracy answered 2/6, 2010 at 4:50 Comment(1)
In addition, the FormBorderStyle can be set to FormBorderStyle.None to remove the border as well, for a more true maximized feeling, no borders added.Insectivorous
S
16

You can use this.WindowState = FormWindowState.Maximized;

Semifinal answered 6/1, 2013 at 9:59 Comment(0)
C
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
Ceremony answered 3/12, 2015 at 10:25 Comment(1)
This line is all you needGeoffrey
G
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();
        }
    }
Gaming answered 31/5, 2017 at 12:18 Comment(0)
C
0

correct in VS2010:

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

Calculating answered 21/4, 2015 at 9:26 Comment(0)
G
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);
    }
Gyrostatic answered 16/5, 2019 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.