How do I maximize a window programmatically so that it cannot be resized once it reaches the maximized state (for example, maximize Internet Explorer and see it)?
I set FormWindowState property as
this.WindowState = FormWindowState.Maximized;
this.MaximizedBounds = (x,y);
but it doesn't work. How do I do this?
The window I want to maximize is a window in my application.
Change the property WindowState
to System.Windows.Forms.FormWindowState.Maximized
, in some cases if the older answers doesn't works.
So the window will be maximized, and the other parts are in the other answers.
When I do this, I get a very small square screen instead of a maxed screen. Yet, when I only use the FormWindowState.Maximized, it does give me a full screen. Why is that?
public partial class Testscherm : Form
{
public Testscherm()
{
this.WindowState = FormWindowState.Maximized;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = this.Size;
this.MaximumSize = this.Size;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
InitializeComponent();
}
To programmatically maximize the windowstate you can use:
this.WindowState = FormWindowState.Maximized;
this.MaximizeBox = false;
To stop the window being resizeable once you've maximised it you need to change the FormBorderStyle
from Sizable
to one of the fixed constants:
FixedSingle
Fixed3D
FixedDialog
From the MSDN Page Remarks section:
The border style of the form determines how the outer edge of the form appears. In addition to changing the border display for a form, certain border styles prevent the form from being sized. For example, the FormBorderStyle.FixedDialog border style changes the border of the form to that of a dialog box and prevents the form from being resized. The border style can also affect the size or availability of the caption bar section of a form.
It will change the appearance of the form if you pick Fixed3D
for example, and you'll probably have to do some work if you want the form to restore to non-maximised and be resizeable again.
When your form is maximized, set its minimum size = max size, so user cannot resize it.
this.WindowState = FormWindowState.Maximized;
this.MinimumSize = this.Size;
this.MaximumSize = this.Size;
You were close... after your code of
WindowState = FormWindowState.Maximized;
THEN, set the form's min/max size capacity to the value once its sized out.
MinimumSize = this.Size;
MaximumSize = this.Size;
Source: Stackoverflow.com