How to: Create a Multipane User Interface with Windows Forms

.NET Framework (current version)

In the following procedure, you will create a multipane user interface that is similar to the one used in Microsoft Outlook, with a Folder list, a Messages pane, and a Preview pane. This arrangement is achieved chiefly through docking controls with the form.

When you dock a control, you determine which edge of the parent container a control is fastened to. Thus, if you set the Dock property to Right, the right edge of the control will be docked to the right edge of its parent control. Additionally, the docked edge of the control is resized to match that of its container control. For more information about how the Dock property works, see How to: Dock Controls on Windows Forms.

This procedure focuses on arranging the SplitContainer and the other controls on the form, not on adding functionality to make the application mimic Microsoft Outlook.

To create this user interface, you place all the controls within a SplitContainer control, which contains a TreeView control in the left-hand panel. The right-hand panel of the SplitContainer control contains a second SplitContainer control with a ListView control above a RichTextBox control. These SplitContainer controls enable independent resizing of the other controls on the form. You can adapt the techniques in this procedure to craft custom user interfaces of your own.

To create an Outlook-style user interface programmatically

  1. Within a form, declare each control that comprises your user interface. For this example, use the TreeView, ListView, SplitContainer, and RichTextBox controls to mimic the Microsoft Outlook user interface.

    private System.Windows.Forms.TreeView treeView1;  
    private System.Windows.Forms.ListView listView1;  
    private System.Windows.Forms.RichTextBox richTextBox1;  
    private System.Windows.Forms. SplitContainer splitContainer2;  
    private System.Windows.Forms. SplitContainer splitContainer1;  
  2. Create a procedure that defines your user interface. The following code sets the properties so that the form will resemble the user interface in Microsoft Outlook. However, by using other controls or docking them differently, it is just as easy to create other user interfaces that are equally flexible.

    public void createOutlookUI()  
        // Create an instance of each control being used.  
        treeView1 = new System.Windows.Forms.TreeView();  
        listView1 = new System.Windows.Forms.ListView();  
        richTextBox1 = new System.Windows.Forms.RichTextBox();  
        splitContainer2 = new System.Windows.Forms.SplitContainer();  
        splitContainer1 = new System.Windows.Forms.SplitContainer();  
        // Insert code here to hook up event methods.  
        // Set properties of TreeView control.  
        treeView1.Dock = System.Windows.Forms.DockStyle.Fill;  
        treeView1.TabIndex = 0;  
        // Set properties of ListView control.  
        listView1.Dock = System.Windows.Forms.DockStyle.Top;  
        listView1.TabIndex = 2;  
        // Set properties of RichTextBox control.  
        richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;  
        richTextBox1.TabIndex = 3;  
        richTextBox1.Text = "richTextBox1";  
        // Set properties of first SplitContainer control.  
        splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;  
        splitContainer2.TabIndex = 1;  
        splitContainer2.SplitterWidth = 4;  
        splitContainer2.SplitterDistance = 150;  
        splitContainer2.Orientation = Orientation.Horizontal;  
        // Set properties of second SplitContainer control.  
        splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;  
        splitContainer2.TabIndex = 4;  
        splitContainer2.SplitterWidth = 4;  
        splitContainer2.SplitterDistance = 100;  
        // Add the main SplitContainer control to the form.  
        this.Text = "Intricate UI Example";  
  3. In Visual Basic, add a call to the procedure you just created in the New() procedure. In Visual C#, add this line of code to the constructor for the form class.

    // Add this to the form class's constructor.  

SplitContainer Control
How to: Create a Multipane User Interface with Windows Forms Using the Designer