Export (0) Print
Expand All
3 out of 3 rated this helpful - Rate this topic

Splitter Class

Represents a splitter control that allows the user to resize docked controls.

For a list of all members of this type, see Splitter Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.Splitter

[Visual Basic]
Public Class Splitter
   Inherits Control
   Implements IMessageFilter
[C#]
public class Splitter : Control, IMessageFilter
[C++]
public __gc class Splitter : public Control, IMessageFilter
[JScript]
public class Splitter extends Control implements IMessageFilter

Thread Safety

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

Remarks

The Splitter control enables you 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 find it desirable 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).

Note   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.

Example

[Visual Basic, C#, C++] The following 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 assumes that the method created in this example is defined within a Form and that the method is called from the constructor of the Form.

[Visual Basic] 
Private Sub CreateMySplitControls()
   ' Create TreeView, ListView, and Splitter controls.
   Dim treeView1 As New TreeView()
   Dim listView1 As New ListView()
   Dim splitter1 As 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.
   Me.Controls.AddRange(New Control() {listView1, splitter1, treeView1})
End Sub 'CreateMySplitControls


[C#] 
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});
}

[C++] 
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(S"TreeView Node");
        listView1->Items->Add(S"ListView Item");

        // Add the controls in reverse order to the form to ensure proper location.

        Control* temp0 [] = {listView1, splitter1, treeView1};
        this->Controls->AddRange(temp0);
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

Splitter Members | System.Windows.Forms Namespace | TreeView | ListView

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.