Use the SplitContainer
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Exam 70-526 Preparation Guide: Use the SplitContainer control to create dynamic container areas.
|
Contents |
The SplitContainer control can be thought of as a composite control; effectively it is two Panel controls separated by a movable bar (also known as a splitter bar). When the mouse pointer is over the bar, the pointer changes shape to show that the bar can be moved.
Controls can be added to either Panel. This arrangement is very effective for displaying and browsing information, as per the Windows Explorer.
When a SplitContainer control is dropped onto a container (e.g. Form or other container control) the Dock property is automatically set to Fill the parent container, since this is the most common usage scenario.
This control allows for vertical or horizontal orientation and provides control over the position of the splitter, the width of the splitter and the splitter increment.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.SplitContainer
Useful properties
-
AutoScroll- This property when set totrue, allows scroll bars to be displayed.
-
-
BackColor- The background colour of theSplitContaineris defaulted toSystem.Drawing.SystemColors.Control, but this can be set to any colour you like. The whole of theSplitContainerchanges colour, however, eachPanelcan have its own background colour.
-
-
BackgroundImage- Instead of a single colour, an image can be displayed as the background. The image only appears in the splitter bar.
-
-
BorderStyle- This property determines if the panel is outlined with no visible border (None), a plain line (FixedSingle), or a shadowed line (Fixed3D).
-
-
Dock- Determines whichSplitContainerborders are attached to the edges of the container. When aSplitContainercontrol is dropped onto a container, this property defaults toFill.
-
-
FixedPanel- Determines whichSplitContainerpanel remains the same size when the container is resized. This property takes a value from theFixedPanelenumeration, the default value isNone:-
None- Specifies that neitherSplitContainer.Panel1,SplitContainer.Panel2is fixed. AControl.Resizeevent affects both panels. -
Panel1- Specifies thatSplitContainer.Panel1is fixed. AControl.Resizeevent affects onlySplitContainer.Panel2. -
Panel2- Specifies thatSplitContainer.Panel2is fixed. AControl.Resizeevent affects onlySplitContainer.Panel1.
-
-
Note:
|
-
IsSplitterFixed- Gets or sets a value indicating whether the splitter is fixed or movable.
-
-
Orientation- Gets or sets a value indicating theHorizontalorVerticalorientation of theSplitContainerpanels.
-
-
Panel1- Gets the left panel of a verticalSplitContaineror the top panel of a horizontalSplitContainer. When you click on this property in the IDE properties pane, you can edit the properties of the underlyingPanel.
-
-
Panel1Collapsed- Determines whetherPanel1is collapsed or expanded. When this value istrue,Panel1is hidden andPanel2expands to fill theSplitContainer. This property is mutually exclusive withPanel2Collapsed.
-
-
Panel1MinSize- Determines the minimum distance in pixels of the splitter from the left or top edge ofPanel1.
-
-
Panel2- Gets the right panel of a verticalSplitContaineror the bottom panel of a horizontalSplitContainer. When you click on this property in the IDE properties pane, you can edit the properties of the underlyingPanel.
-
-
Panel2Collapsed- Determines whetherPanel2is collapsed or expanded. When this value is true,Panel2is hidden and Panel1 expands to fill theSplitContainer. This property is mutually exclusive withPanel1Collapsed.
-
-
Panel2MinSize- Determines the minimum distance in pixels of the splitter from the right or bottom edge ofPanel2.
-
-
SplitterDistance- Determines the location of the splitter, in pixels, from the left (Orientation = Vertical) or top (Orientation = Horizontal) edge of theSplitContainer.
-
-
SplitterIncrement- Gets or sets a value representing the increment of splitter movement in pixels.
-
-
SplitterRectangle- Gets the size and location of the splitter relative to theSplitContainer.
-
-
SplitterWidth- Determines the width of the splitter in pixels.
-
SplitContainer Tasks
Clicking on the Smart Tag icon
causes a small menu to appear.
The menus items are fairly self explanatory. If you click on Undock in parent container, the form changes to something similar to this.
Adding a SplitContainer manually
The following code sample shows very simply how to add a SplitContainer to a Form.
public void CreateMySplitContainer() { SplitContainer splitContainer1 = new SplitContainer(); splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; splitContainer1.Location = new System.Drawing.Point(0, 0); splitContainer1.Name = "splitContainer1"; splitContainer1.BorderStyle = BorderStyle.Fixed3D; this.Controls.Add(splitContainer1); }
Add a control to a SplitContainer manually
Within the above method, a TreeView control can be added like this.
TreeView treeView1 = new TreeView(); treeView1.Dock = DockStyle.Fill; treeView1.ForeColor = SystemColors.InfoText; treeView1.Location = new System.Drawing.Point(0, 0); treeView1.Name = "treeView1"; // Add TreeView control to Panel1 of SplitContainer splitContainer1.Panel1.Controls.Add(treeView1);
Outside of the method, splitContainer1 must be a private member of the Form.
MSDN references
|



