Programmatically adjust the position of the splitter in a SplitContainer control in C#
You can use the SplitContainer's Panel1Collapsed and Panel2Collapsed properties to collapse one of the panels and make it disappear. While a panel is collapsed, the user cannot adjust the splitter.
The following code makes the left panel disappear in a horizontal SplitContainer.
SplitContainer1.Panel1Collapsed = true;To set the splitter to a particular position, set the SplitContainer's SplitterDistance property. Be sure to un-collapse any panels that you may have collapsed. The following code moves the splitter to 25% of the way through the SplitContainer.
SplitContainer1.Panel1Collapsed = false;In the example program, click the buttons to collapse a panel or move the splitter to 25%, 50%, or 75% of the way through the SplitContainer.
SplitContainer1.Panel2Collapsed = false;
SplitContainer1.SplitterDistance = (int)(SplitContainer1.ClientSize.Width * 0.25);



Comments