10

I have a WinForm containing a bindingNavigator at the top and a splitContainer with two horisontal panels below it. The splitContainer fills the space not occupied by the bindingNavigator.

I would like to set the bottom panel to a fixed height of, say 100 pixels, and have the top panel fill the rest of the space.

This is my current code:

kundeteamSplitContainer.SplitterDistance = kundeteamSplitContainer.Height - 100;

I would have thought that this would set the splitter distance dynamically to 100 pixels less than the total height at all times, making the bottom panel occupy the remaining 100 pixels. This does not work as intended though as the bottom panel keeps changing size when I re-size the form at run-time.

EDIT: I am sticking with the splitContainer if at all possible. Got a bunch of functionality related to hiding/showing the bottom panel already implemented and I don't want to do that work again.

Sakkle
  • 1,934
  • 9
  • 27
  • 39

5 Answers5

27

Set the FixedPanel property to the panel you want to remain the same size.

Lee
  • 142,018
  • 20
  • 234
  • 287
20

As pointed out by Lee:

Set the FixedPanel property to the panel you want to remain the same size.

This works like this:

teamSplitContainer.SplitterDistance = teamSplitContainer.Height - 100;
teamSplitContainer.FixedPanel = FixedPanel.Panel2;
Sakkle
  • 1,934
  • 9
  • 27
  • 39
3

Best way you can set isSplitterFixed Property to "True"

Property Window for splitcontainer

Sachith Wickramaarachchi
  • 5,546
  • 6
  • 39
  • 68
2

I'd use a TableLayoutControl for something like this rather than a Splitter.

MartW
  • 12,348
  • 3
  • 44
  • 68
  • Well.. that may very well be, but I'm not changing at this point. My more experienced colleagues told me to use a splitter, so I'll stick to it for now. – Sakkle Sep 03 '09 at 14:16
  • Fair enough. I've only used the VS2005 version and found it a bit too buggy. – MartW Sep 03 '09 at 15:33
  • @Sakkle: But if the only requirement is keeping the panel-hiding code, you can set the TableLayoutPanel's row height to 0 and it'd work pretty much the same... – C.B. May 27 '13 at 12:38
0

If you want only show and disable the panel (no automatic resize, no resize by the user) add to the code by Sakkle this line:

teamSplitContainer.IsSplitterFixed = true;
Julo
  • 1,102
  • 1
  • 11
  • 19