Question

I have to modify the size of my main form depending on which tab is selected. The below code is working except if the form window is maximized. It would be a solution to 'exit' that maximization first, and then modify the size. How to approach that?

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (tabControl1.SelectedIndex == 0)
        {
            this.Width = x;
            this.Height = y;
        }
        else if (tabControl1.SelectedIndex == 1)
        {
            this.Width = x;
            this.Height = y;
        }
    }
Was it helpful?

Solution

you have to set Form.WindowState However I don't think that it is a good idea to undo maximization and change form size at runtime.

OTHER TIPS

if (WindowState == FormWindowState.Maximised)
{
    WindowState = FormWindowState.Normal;
}

// Now you can change the size.
this.Width = x;
this.Height = y;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top