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 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); }
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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.