Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ToolBar.ToolBarButtonCollection Class

Encapsulates a collection of ToolBarButton controls for use by the ToolBar class.

For a list of all members of this type, see ToolBar.ToolBarButtonCollection Members.

System.Object
   System.Windows.Forms.ToolBar.ToolBarButtonCollection

[Visual Basic]
Public Class ToolBar.ToolBarButtonCollection
   Implements IList, ICollection, IEnumerable
[C#]
public class ToolBar.ToolBarButtonCollection : IList, ICollection,
   IEnumerable
[C++]
public __gc class ToolBar.ToolBarButtonCollection : public IList,
   ICollection, IEnumerable
[JScript]
public class ToolBar.ToolBarButtonCollection implements IList,
   ICollection, IEnumerable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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.

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

Namespace: System.Windows.Forms

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

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.