Export (0) Print
Expand All

Splitter Class

Represents a splitter control that enables the user to resize docked controls. Splitter has been replaced by SplitContainer and is provided only for compatibility with previous versions.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class Splitter : Control

The Splitter control enables the user to resize controls that are docked to the edges of the Splitter control at run time. When the user passes the mouse pointer over the Splitter control, the cursor changes to indicate that the controls docked to the Splitter control can be resized. The Splitter control enables the user to resize the docked control that is immediately before it in the docking order. Therefore, to enable the user to resize a docked control, dock the control you want the user to be able to resize to an edge of a container, and then dock a splitter to the same side of that container. For example, to create a window similar to Windows Explorer, add a TreeView control to a form and set its Dock property to DockStyle.Left. Add a Splitter control to the form and set its Dock property to DockStyle.Left as well. To complete the form layout, add a ListView control and set its Dock property to DockStyle.Fill to have the ListView occupy the remaining space on the form. At run time, the user can then resize the width of the TreeView control (as well as the ListView control) by moving the Splitter control.

To ensure that the Splitter control does not resize controls docked to a size that is too small to be useful to the user, you use the MinExtra and MinSize properties. The MinExtra and MinSize properties determine the minimum size that controls docked to the left and right (or top and bottom if a horizontal Splitter control) can be sized to. If the other controls on your form that the Splitter control is docked to display a specific style of border, you can use the BorderStyle property to match the border style of the controls that are docked to it.

You might want to set a maximum size limit on controls that the Splitter control is docked to. The SplitterMoved and SplitterMoving events enable you to determine when the user is resizing a docked control. You can use the SplitPosition property in an event handler for the SplitterMoved or SplitterMoving events to determine the size of the control that the Splitter control is docked to and set the SplitPosition property to a different value to limit the docked control's width to a specified maximum width (or height if a horizontally aligned Splitter control).

NoteNote:

Resizing a control using the Splitter control can only be done using the mouse. It is not possible to access the Splitter control using the keyboard.

The following code example uses a Splitter control in combination with TreeView and ListView controls to create a window similar to Windows Explorer. To identify the TreeView and ListView controls, nodes and items are added to both controls. The example uses the MinExtra and MinSize properties of the Splitter to prevent the TreeView or ListView control from being sized too small or too large. This example requires that the method created in this example is defined within a Form and that the method is called from the constructor of the Form.

		private void CreateMySplitControls()
		{
			// Create TreeView, ListView, and Splitter controls.
			TreeView treeView1 = new TreeView();
			ListView listView1 = new ListView();
			Splitter splitter1 = new Splitter();

			// Set the TreeView control to dock to the left side of the form.
			treeView1.Dock = DockStyle.Left;
			// Set the Splitter to dock to the left side of the TreeView control.
			splitter1.Dock = DockStyle.Left;
			// Set the minimum size the ListView control can be sized to.
			splitter1.MinExtra = 100;
			// Set the minimum size the TreeView control can be sized to.
			splitter1.MinSize = 75;
			// Set the ListView control to fill the remaining space on the form.
			listView1.Dock = DockStyle.Fill;
			// Add a TreeView and a ListView item to identify the controls on the form.
            treeView1.Nodes.Add("TreeView Node");
            listView1.Items.Add("ListView Item");

			// Add the controls in reverse order to the form to ensure proper location. 
			this.Controls.AddRange(new Control[]{listView1, splitter1, treeView1});
		}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft