Export (0) Print
Expand All

ToolStripContainer Class

Provides panels on each side of the form and a central panel that can hold one or more controls.

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

[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class ToolStripContainer : ContainerControl

ToolStripContainer is similar to SplitContainer. It uses four docked side panels (instances of ToolStripPanel) and one central panel (an instance of ToolStripContentPanel) to create a typical arrangement. You cannot remove the side panels, but you can hide them by setting their respective TopToolStripPanelVisible, BottomToolStripPanelVisible, LeftToolStripPanelVisible, and RightToolStripPanelVisible properties to false. By default, each of these properties is true at design time. Also at design time, the ToolStripContainer appears with its top panel already expanded. You can neither remove nor hide the ToolStripContentPanel. You can arrange one or more ToolStrip, MenuStrip, or StatusStrip controls in the side panels, and you can use the central panel for other controls. The ToolStripContentPanel also provides a way to get renderer support into the body of your form for a consistent appearance.

ToolStripContainer does not support Multiple Document Interface (MDI) applications. Use ToolStripPanel for MDI applications.

The following code example demonstrates adding a ToolStripContainer and a ToolStrip to a Windows Forms, adding items to the ToolStrip, and adding the ToolStrip to the TopToolStripPanel of the ToolStripContainer.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


public class Form1 : Form
{
    private ToolStripContainer toolStripContainer1;
    private ToolStrip toolStrip1;

    public Form1()
    {
        InitializeComponent();
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }

    private void InitializeComponent()
    {
        toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
        toolStrip1 = new System.Windows.Forms.ToolStrip();
        // Add items to the ToolStrip.
        toolStrip1.Items.Add("One");
        toolStrip1.Items.Add("Two");
        toolStrip1.Items.Add("Three");
        // Add the ToolStrip to the top panel of the ToolStripContainer.
        toolStripContainer1.TopToolStripPanel.Controls.Add(toolStrip1);
        // Add the ToolStripContainer to the form.
        Controls.Add(toolStripContainer1);

    }
}

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

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

Community Additions

ADD
Show:
© 2014 Microsoft