Winforms control combining best of both the SplitContainer and TableLayoutPanel

2.9k views Asked by At

With a SplitContainer, the user can resize the two sides of the control. But it's only limited to two sections.

With a TableLayoutPanel you have unlimited rows and columns. Unfortunately, the user can't drag any of these sections around.

How can I have the best of boths worlds; the 'draggable-ness' of the middle bar in the SplitContainer and the ability to have more than 2x1 sections as the TableLayoutPanel allows?

If Winforms won't allow it, perhaps there's a commercial component out there? I know that I've seen this sort of advanced control in some non-.NET programs.

2

There are 2 answers

3
Brody On BEST ANSWER

Embed another SplitContainer inside one half of the first one.

Remember you can split horizontal as well as vertical. I am sure a lot of neat layouts can be generated that way.

0
tsemer On

Building on top of @Brody's solution:

After embedding another SplitContainer(s), the only drawback as mentioned by @Wolf5 is that they don't automatically resize together, so you quickly lose the tabular view. A solution could be to set up a SplitterMoved event handler for every applicable SplitContainer:

private void mySplitContainer_SplitterMoved(object sender, SplitterEventArgs e) {
  mOtherySplitContainer.SplitterDistance = e.SplitX;
}

If your SplitContainer is horizontal use e.SplitX, if it's vertical use e.SplitY.


Suggested duplicate of this other question: Resizable table layout panel in c#