ToolBar.Buttons Property

Definition

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

C#
public System.Windows.Forms.ToolBar.ToolBarButtonCollection Buttons { get; }

Property Value

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

Examples

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.

C#
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.
    toolBar1.Buttons.Add(toolBarButton1);
    toolBar1.Buttons.Add(toolBarButton2);
    toolBar1.Buttons.Add(toolBarButton3);
 
    // Add the ToolBar to the Form.
    Controls.Add(toolBar1);
 }

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0

See also