Search code examples
c#winformsflowlayoutpanelsplitcontainer

How do I add a SplitContainer dynamically c#


At design time I have a form with a FlowLayoutPanel. I can create buttons inside it with no problems. But when I tried to add a SplitContainer, nothing happens.

Later I will need to add a Splitcontainer inside another SplitContainer. So my user can choose the number of sections (panels) he wants to see in the form.

I'm trying this:

        SplitContainer spltcnt = new SplitContainer();
        spltcnt.Dock = DockStyle.Fill;
        spltcnt.Orientation = Orientation.Horizontal;
        spltcnt.SplitterWidth = 100;
        spltcnt.Visible = true;

        flwLayoutPanel.Controls.Add(spltcnt);

Solution

  • You can't dock in a FlowLayoutPanel as per this SO question (among others). You will have to manually set the Height and Width of your SplitContainers when the form is resized.