Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ToolBar.Buttons Property

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; }

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft