SplitContainer in C#



If you have ever written Outlook type user interfaces using Windows Forms, you must be familiar with Splitter control. The Splitter control used to provide functionality to split two controls and dock them.  Now Windows Forms 2.0, that ships with Visual Studio 2005 replaces Splitter control with a new control called SplitContainer.

SplitContainer is a combination of panels and a splitter control. Two panels are separated by the splitter control. The default SplitContainer is shown in Figure 1.
 

SplitContainer1.jpg 
Figure 1. SplitContainer control

In Figure 1, you can see there is a left panel (Panel1) and there is a right panel (Panel2) separated by a splitter. Now to create an Outlook type application, I drop one more SplitContainer on the right panel of SplitContainer1. By default the orientation of SplitContainer is vertical. I set it to Horizontal. See Figure 2. 

SplitContainer2.jpg
Figure 2. Adding second SplitContainer with Orientation = Horizontal.

Now I change the color of various panels so they can be easily identified. Now the final form looks like Figure 3. You can resize the panels by using the splitter. 

SplitContainer3.jpg
Figure 3. Outlook style application.

Now you can drop TreeView, ListBox, DataGrid and other controls on these various panels and create the application whatever way you want.

Up Next
    Ebook Download
    View all
    Learn
    View all