Export (0) Print
Expand All

ToolBar.Buttons Property

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

[Visual Basic]
Public ReadOnly Property Buttons As ToolBar.ToolBarButtonCollection
[C#]
public ToolBar.ToolBarButtonCollection Buttons {get;}
[C++]
public: __property ToolBar.ToolBarButtonCollection* get_Buttons();
[JScript]
public function get Buttons() : ToolBar.ToolBarButtonCollection;

Property Value

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

Remarks

The Buttons property is a zero-based indexed collection used to hold all the ToolBarButton controls assigned to the toolbar. Since 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.

Example

[Visual Basic, C#, C++] The following 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 assumes that a Form has already been created.

[Visual Basic] 
Public Sub InitializeMyToolBar()
    ' Create and initialize the ToolBarButton controls and ToolBar.
    Dim toolBar1 As New ToolBar()
    Dim toolBarButton1 As New ToolBarButton()
    Dim toolBarButton2 As New ToolBarButton()
    Dim toolBarButton3 As 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)
End Sub


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


[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 = S"Open";
    toolBarButton2->Text = S"Save";
    toolBarButton3->Text = S"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);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

ToolBar Class | ToolBar Members | System.Windows.Forms Namespace | ToolBar.ToolBarButtonCollection

Show:
© 2015 Microsoft