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?
How can you make the form maximize to any computer screen in a Windows Forms application?
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
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;
WindowState = FormWindowState.Maximized; // not WindowState=Maximized; as for PrimaryScreen work alwyas only if one display or all other display do not have smaller size –
Odaniel
You don't need to set Width and Height if state is Maximized. That does it alone –
Geoffrey
Set the WindowState property of your form to Maximized
.
That will cause your form to be maximumized when it's opened.
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 You can use this.WindowState = FormWindowState.Maximized;
- 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
This line is all you need –
Geoffrey
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();
}
}
correct in VS2010:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
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);
}
© 2022 - 2024 — McMap. All rights reserved.