ToolBar.ToolBarButtonCollection Class
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The ToolBar.ToolBarButtonCollection is a zero-based indexed collection used by the ToolBar class to hold all the ToolBarButton controls assigned to the toolbar. Use the Add method to add individual buttons and the Remove method to delete them. 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 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
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.set_Text("Open");
toolBarButton2.set_Text("Save");
toolBarButton3.set_Text("Print");
// Add the ToolBarButton controls to the ToolBar.
toolBar1.get_Buttons().Add(toolBarButton1);
toolBar1.get_Buttons().Add(toolBarButton2);
toolBar1.get_Buttons().Add(toolBarButton3);
// Add the ToolBar to the Form.
get_Controls().Add(toolBar1);
} //InitializeMyToolBar
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.