3

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.

Dan W
  • 3,520
  • 7
  • 42
  • 69

2 Answers2

3

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.

Brody
  • 2,074
  • 1
  • 18
  • 23
  • This seems almost too easy. I'll try it out and get back to you. – Dan W Jun 29 '15 at 04:06
  • Well that was quick. I don't think I can find any drawback so far. Nicely done. Now it's just a matter whether I should put two horizontal SplitContainers inside a vertical or two vertical SplitContainers inside a horizontal, but that's my problem :) – Dan W Jun 29 '15 at 04:20
  • The only drawback when you have 2+ split lines that you can drag, you'll see quickly. Dragging one of the splitters will only affect that splitcontainer and child containers and not the parent splitcontainer. So you dont get a perfect "TableLayoutPanel" with splitters, but it works. – Wolf5 Jun 29 '15 at 06:08
1

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#

tsemer
  • 2,959
  • 3
  • 29
  • 26