Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys

I have been trying to programmatically re-size a c# winforms form.

I have achieved this using:

this.Size = new Size(900, 900);

But this does not work when the window is maximized.

Any ideas how I can get the form to re-size when it's in the maximized state ??

Thanks in advance,
Baxter.
Posted
Comments
joshrduncan2012 22-Jul-13 10:38am    
I think you are looking for the windowstate property.

If you want to re-size the window while keeping the maximized state, then you're doing it wrong.

But I'm assuming rather that you want to re-size it from a maximized state. In this case, you just have to do as joshduncan2012 suggested, and change the windowstate back to normal.

C#
this.WindowState = FormWindowState.Normal;
this.Size = new Size(yourWidth,yourHeight);
 
Share this answer
 
v2
It should work as soon as "this" references your form and it is not maximized or minimized. Another option is to set the values of the form's properties Width and Heigh.

—SA
 
Share this answer
 
v2
Hi Guys,

Thanks for the help.

Here is the working solution I have found with your help:

C#
if (this.WindowState == FormWindowState.Maximized)
{
    this.WindowState = FormWindowState.Minimized;
    this.WindowState = FormWindowState.Normal;
    this.BringToFront();
}
else
{
    Int32 width = this.Width;
    Int32 height = this.Height;
    this.Size = new System.Drawing.Size(902, 907);
    this.Size = new System.Drawing.Size(width, height);
}
Many Thanks.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900