Export (0) Print
Expand All

How to: Define Resize and Positioning Behavior in a Split Window

.NET Framework 3.0

The panels of the SplitContainer control lend themselves well to being resized and manipulated by users. However, there will be times when you will want to programmatically control the splitter—where it is positioned and to what degree it can be moved.

The SplitterIncrement property and the other properties on the SplitContainer control give you precise control over the behavior of your user interface to suit your needs. These properties are listed in the following table.

Name Description

IsSplitterFixed property

Determines if the splitter is movable by means of the keyboard or mouse.

SplitterDistance property

Determines the distance in pixels from the left or upper edge to the movable splitter bar.

SplitterIncrement property

Determines the minimum distance, in pixels, that the splitter can be moved by the user.

The example below modifies the SplitterIncrement property to create a "snapping splitter" effect; when the user drags the splitter, it increments in units of 10 pixels rather than the default 1.

To define SplitContainer resize behavior

  • In a procedure, set the SplitterIncrement property to the desired size, so that the 'snapping' behavior of the splitter is achieved.

    In the following code example, within the form's Load event, the splitter within the SplitContainer control is set to jump 10 pixels when dragged.

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        Dim splitSnapper as new SplitContainer()
        splitSnapper.SplitterIncrement = 10
        splitSnapper.Dock = DockStyle.Fill
        splitSnapper.Parent = me
    End Sub
    
    

    private void Form1_Load(System.Object sender, System.EventArgs e)
    {
        SplitContainer splitSnapper = new SplitContainer();
        splitSnapper.SplitterIncrement = 10;
        splitSnapper.Dock = DockStyle.Fill;
        splitSnapper.Parent = this;
    }
    

    (Visual C#) Place the following code in the form's constructor to register the event handler.

    this.Load += new System.EventHandler(this.Form1_Load);
    

    Moving the splitter slightly to the left or right will have no discernible effect; however, when the mouse pointer goes 10 pixels in either direction, the splitter will snap to the new position.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft