Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Create a Multipane User Interface
ms.date: "03/30/2017"
description: Describes how to layout Windows Forms controls to mimic a Microsoft Outlook email application.
ms.date: 01/21/2022
dev_langs:
- "csharp"
- "vb"
Expand All @@ -14,162 +15,53 @@ helpviewer_keywords:
ms.assetid: e79f6bcc-3740-4d1e-b46a-c5594d9b7327
---
# How to: Create a Multipane User Interface with Windows Forms
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 <xref:System.Windows.Forms.SplitContainer.Dock%2A> property to <xref:System.Windows.Forms.DockStyle.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 <xref:System.Windows.Forms.SplitContainer.Dock%2A> property works, see [How to: Dock Controls on Windows Forms](how-to-dock-controls-on-windows-forms.md).

This procedure focuses on arranging the <xref:System.Windows.Forms.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 <xref:System.Windows.Forms.SplitContainer> control, which contains a <xref:System.Windows.Forms.TreeView> control in the left-hand panel. The right-hand panel of the <xref:System.Windows.Forms.SplitContainer> control contains a second <xref:System.Windows.Forms.SplitContainer> control with a <xref:System.Windows.Forms.ListView> control above a <xref:System.Windows.Forms.RichTextBox> control. These <xref:System.Windows.Forms.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 <xref:System.Windows.Forms.TreeView>, <xref:System.Windows.Forms.ListView>, <xref:System.Windows.Forms.SplitContainer>, and <xref:System.Windows.Forms.RichTextBox> controls to mimic the Microsoft Outlook user interface.

```vb
Private WithEvents treeView1 As System.Windows.Forms.TreeView
Private WithEvents listView1 As System.Windows.Forms.ListView
Private WithEvents richTextBox1 As System.Windows.Forms.RichTextBox
Private WithEvents splitContainer1 As _
System.Windows.Forms.SplitContainer
Private WithEvents splitContainer2 As _
System.Windows.Forms.SplitContainer
```

```csharp
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.

```vb
Public Sub CreateOutlookUI()
' Create an instance of each control being used.
Me.components = New System.ComponentModel.Container()
Me.treeView1 = New System.Windows.Forms.TreeView()
Me.listView1 = New System.Windows.Forms.ListView()
Me.richTextBox1 = New System.Windows.Forms.RichTextBox()
Me.splitContainer1 = New System.Windows.Forms.SplitContainer()
Me.splitContainer2= New System.Windows.Forms. SplitContainer()

' Should you develop this into a working application,
' use the AddHandler method to hook up event procedures here.

' Set properties of TreeView control.
' Use the With statement to avoid repetitive code.
With Me.treeView1
.Dock = System.Windows.Forms.DockStyle.Fill
.TabIndex = 0
.Nodes.Add("treeView")
End With

' Set properties of ListView control.
With Me.listView1
.Dock = System.Windows.Forms.DockStyle.Top
.TabIndex = 2
.Items.Add("listView")
End With

' Set properties of RichTextBox control.
With Me.richTextBox1
.Dock = System.Windows.Forms.DockStyle.Fill
.TabIndex = 3
.Text = "richTextBox1"
End With

' Set properties of the first SplitContainer control.
With Me.splitContainer1
.Dock = System.Windows.Forms.DockStyle.Fill
.TabIndex = 1
.SplitterWidth = 4
.SplitterDistance = 150
.Orientation = Orientation.Horizontal
.Panel1.Controls.Add(Me.listView1)
.Panel2.Controls.Add(Me.richTextBox1)
End With

' Set properties of the second SplitContainer control.
With Me.splitContainer2
.Dock = System.Windows.Forms.DockStyle.Fill
.TabIndex = 4
.SplitterWidth = 4
.SplitterDistance = 100
.Panel1.Controls.Add(Me.treeView1)
.Panel2.Controls.Add(Me.SplitContainer1)
End With

' Add the main SplitContainer control to the form.
Me.Controls.Add(Me.splitContainer2)
Me.Text = "Intricate UI Example"
End Sub
```

```csharp
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;
treeView1.Nodes.Add("treeView");

// Set properties of ListView control.
listView1.Dock = System.Windows.Forms.DockStyle.Top;
listView1.TabIndex = 2;
listView1.Items.Add("listView");

// 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;
splitContainer2.Panel1.Controls.Add(this.listView1);
splitContainer2.Panel1.Controls.Add(this.richTextBox1);

// Set properties of second SplitContainer control.
splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
splitContainer2.TabIndex = 4;
splitContainer2.SplitterWidth = 4;
splitContainer2.SplitterDistance = 100;
splitContainer2.Panel1.Controls.Add(this.treeView1);
splitContainer2.Panel1.Controls.Add(this.splitContainer1);

// Add the main SplitContainer control to the form.
this.Controls.Add(this.splitContainer2);
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.

```vb
' Add this to the New procedure.
CreateOutlookUI()
```

```csharp
// Add this to the form class's constructor.
createOutlookUI();
```


By arranging controls on a form, you can create a multi-pane user interface that's 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. If you set the <xref:System.Windows.Forms.SplitContainer.Dock%2A> property to <xref:System.Windows.Forms.DockStyle.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 <xref:System.Windows.Forms.SplitContainer.Dock%2A> property works, see [How to: Dock Controls on Windows Forms](how-to-dock-controls-on-windows-forms.md).

This procedure focuses on arranging the <xref:System.Windows.Forms.SplitContainer> and the other controls on the form, not on adding functionality to make the application mimic Microsoft Outlook.

:::image type="content" source="media/how-to-create-a-multipane-user-interface-with-windows-forms/form.png" alt-text="A form that's designed to look like an Outlook mail window.":::

To create this user interface, you place all the controls within a <xref:System.Windows.Forms.SplitContainer> control. The `SplitContainer` contains a <xref:System.Windows.Forms.TreeView> control in the left-hand panel and another `SplitContainer` on the right-hand panel. The second `SplitContainer` contains a <xref:System.Windows.Forms.ListView> control on top and a <xref:System.Windows.Forms.RichTextBox> control on the bottom.

These <xref:System.Windows.Forms.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.

## Control layout

The following table describes how the controls are configured to mimic Microsoft Outlook:

| Control | Property | Value |
|----------------|------------------|--------------------------------------------------|
| SplitContainer | Name | `splitContainer1` |
| | Dock | `Fill` |
| | TabIndex | `4` |
| | SplitterWidth | `4` |
| | SplitterDistance | `100` |
| | Panel1.Controls | Add the `treeView1` control to this panel. |
| | Panel2.Controls | Add the `splitContainer2` control to this panel. |
| TreeView | Name | `treeView1` |
| | Dock | `Fill` |
| | TabIndex | `0` |
| | Nodes | Add a new node named `Node0` |
| SplitContainer | Name | `splitContainer2` |
| | Dock | `Fill` |
| | TabIndex | `1` |
| | SplitterWidth | `4` |
| | SplitterDistance | `150` |
| | Orientation | `Horizontal` |
| | Panel1.Controls | Add the `listView1` control to this panel. |
| | Panel2.Controls | Add the `richTextBox1` control to this panel. |
| ListView | Name | `listView1` |
| | Dock | `Fill` |
| | TabIndex | `2` |
| | Items | Add a new item and set the text to `item1`. |
| RichTextBox | Name | `richTextBox1` |
| | Dock | `Fill` |
| | TabIndex | `3` |
| | Text | `richTextBox1` |

## See also

- <xref:System.Windows.Forms.SplitContainer>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace project
{
public partial class Form1 : Form
{
//Windows Form application
public Form1()
{
InitializeComponent();
}
}
}
Loading