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?
Asked
Active
Viewed 8.1k times
24
-
2I'm sure you mean when run, not compiled. – Jean-Bernard Pellerin Jun 02 '10 at 04:49
-
2the answer depends on what platform you are coding for. WPF? Silverlight? WinForms? etc. – Muad'Dib Jun 02 '10 at 04:49
7 Answers
38
You can do it using one of the following --
- Set the form WindowState = FormWindowState.Maximized;
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;
-
4WindowState = 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
-
1In 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
7
- 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();
}
}

amr_elshafei
- 51
- 2
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