tags:

views:

96

answers:

4

hi

i want to maximize a window programmatically so that it cannot be resized once it reaches the maximized state(for ex: maximize the internet explorer and see it), i want to do it. i set FormWindowState property as

this.WindowState = FormWindowState.Maximized;
this.MaximizedBounds = (x,y);

but it doesn't work.how to do this.

the window i want to maximize is a window in my application

A: 

programically maximize the windowsate use

WindowState = FormWindowState.Maximized;
this.MaximizeBox = false;
anishmarokey
see my question, i already put this line
karthik
what you used is formawindowstate what is this your form name ?
anishmarokey
sorry,a bit complacent while typing, i used the same property in my code ,it gets maximized but i am able to resize the window after it gets maximized,i want to cut that behaviour
karthik
+2  A: 

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;
Ram
i dont want my form gets moved ,once it is maximized,it should perfectly fit it in to the primaryscreen's working area(just like the internet explorer got maximized)
karthik
A: 

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.

ChrisF
when my form gets maximized,no one should move the form from its location,it should entirely occupies the primaryscreen's working area. i really need to achieve this
karthik
A: 

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;
DRapp
you can simple write as well `MinimumSize = MaximumSize = this.Size;`
balexandre
@balexandre, yes, but at his reputation at 58, I didn't want to possibly confuse the person with how multiple assignments can work in a single stream of variables.
DRapp