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.
Modify form size at runtime while it's maximized
-
21-07-2023 - |
Frage
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;
}
}
Lösung
Andere Tipps
if (WindowState == FormWindowState.Maximised)
{
WindowState = FormWindowState.Normal;
}
// Now you can change the size.
this.Width = x;
this.Height = y;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow