Clock Clock -4 years ago 61
C# Question

Does the Split container control automatically resize the form?

Currently i am using a split container control from windows forms and a button which hides / shows the panel1 or panel2 of the split container when it is cliked. The panel1 and panel2 are having different heights on the main form.

The problem is that the main form which holds the split container is not automatically resized once a panel gets hidden.

Is there an option on the split container that can also resize the height of the parent control ? Or some of you know how to handle this resize of the form once one of the panels of the spllit container gets hidden or shown ?

Answer Source

Just place the Panels directly onto the Form and set their Location() property to the same value (make sure one isn't nested within the other). Make one of them initially hidden and then toggle their visibility at run-time. This can make designing the form a little tricky!

Set the AutoSize property of the Form to True, and the AutoSizeMode property to GrowAndShrink:

    private void button1_Click_1(object sender, EventArgs e)
        panel1.Visible = !panel1.Visible;
        panel2.Visible = !panel2.Visible;

My test form automatically changed sizes to accommodate the size of the currently visible panel.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download