Windows Develop Bookmark and Share   
 index > Windows Forms General > Changing the Form Size when WindowState is Maximized
 

Changing the Form Size when WindowState is Maximized

Hi,

In normal scenario when the form is Maximized it occupies the complete screen. I have required where the form is some displayed as normal form and sometimes toggled to size of a Toolbar.

I achieve this by changing the Form.Size. This works when the WindowState.Normal. However when the Form is WindowState.Maximized the size property is not reflected.

To work around this I follow these step,
- I change the Form.MaximumSize to the required size
- Change the WindowState to Normal
- Set the Form.Size property
- And reset the WindowState to Maximized

But this cause lot of flickering. Is there a better way of acheiving this result?

Thanks
bbusa  Thursday, January 24, 2008 2:38 PM

Hi bbusa,

Based on my understanding, you want to set the size of a form when the form is maximized, don’t you? If so, you can try to use the SetWindowPos API to set the size of the form, this function changes the size, position, and Z order of a child, pop-up, or top-level window. Here is a sample for your information.

Code Snippet

[DllImport("user32.dll")]

static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X,

int Y, int cx, int cy, uint uFlags);

const uint SWP_NOMOVE = 0x0002;

const uint SWP_NOZORDER = 0x0004;

private void button1_Click(object sender, EventArgs e)

{

int width = int.Parse(this.textBox1.Text);

int height = int.Parse(this.textBox2.Text);

SetWindowPos(this.Handle, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Monday, January 28, 2008 5:41 AM

Hi bbusa,

Based on my understanding, you want to set the size of a form when the form is maximized, don’t you? If so, you can try to use the SetWindowPos API to set the size of the form, this function changes the size, position, and Z order of a child, pop-up, or top-level window. Here is a sample for your information.

Code Snippet

[DllImport("user32.dll")]

static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X,

int Y, int cx, int cy, uint uFlags);

const uint SWP_NOMOVE = 0x0002;

const uint SWP_NOZORDER = 0x0004;

private void button1_Click(object sender, EventArgs e)

{

int width = int.Parse(this.textBox1.Text);

int height = int.Parse(this.textBox2.Text);

SetWindowPos(this.Handle, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Monday, January 28, 2008 5:41 AM

You can use google to search for other answers

Custom Search

More Threads

• how do i can open a form from a previous one
• active x control
• How to Resize a ToolStrip-control?
• Turn Redraw of a control/form OFF?
• setting label value in formview verses outside the formview control
• Display Live Video inside a form
• Windows Forms Tab Control problem !!
• Visual Studio.Net after 1.0 -> 1.1 Upgrade
• Please help
• ComboBoxes and DataSet in C#