ToolBar.Buttons Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the collection of ToolBarButton controls assigned to the toolbar control.

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

public ToolBar.ToolBarButtonCollection Buttons { get; }

Property Value

Type: System.Windows.Forms.ToolBar.ToolBarButtonCollection

A ToolBar.ToolBarButtonCollection that contains a collection of ToolBarButton controls.

The Buttons property is a zero-based indexed collection used to hold all the ToolBarButton controls assigned to the toolbar. Because the property is read-only, it can not be assigned a collection of toolbar buttons directly. Toolbar buttons can be added or removed by using the methods inherited from the ToolBar.ToolBarButtonCollection class. Use the Add method to add individual buttons and the Remove method to delete a button. Call the Clear method to remove all the buttons from the collection.

The following code example creates and initializes a ToolBar and three ToolBarButton controls. The toolbar buttons are assigned to the toolbar and the toolbar is added to the form. This code requires that a Form has already been created.

public void InitializeMyToolBar()
    // Create and initialize the ToolBarButton controls and ToolBar.
    ToolBar toolBar1 = new ToolBar();
    ToolBarButton toolBarButton1 = new ToolBarButton();
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();

    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open";
    toolBarButton2.Text = "Save";
    toolBarButton3.Text = "Print";

    // Add the ToolBarButton controls to the ToolBar.

    // Add the ToolBar to the Form.

.NET Framework
Available since 1.1
Return to top