Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ToolBar.ToolBarButtonCollection.Clear Method

Removes all buttons from the toolbar button collection.

[Visual Basic]
Public Overridable Sub Clear() Implements IList.Clear
public virtual void Clear();
public: virtual void Clear();
public function Clear();




The Clear method iterates through the collection and removes all toolbar buttons assigned to the ToolBar.ToolBarButtonCollection.

To remove an individual toolbar button from the collection, use the Remove or RemoveAt methods.

To add new ToolBarButton objects to the collection, use the Add, AddRange or Insert methods.


[Visual Basic, C#, C++] The following example displays the Count of the Buttons before and after the Clear method is called. This code assumes a ToolBar with at least one ToolBarButton has been created.

[Visual Basic] 
Public Sub ClearMyToolBar()
    Dim btns As Integer
    ' Get the count before the Clear method is called.
    btns = toolBar1.Buttons.Count
    MessageBox.Show("Count Before Clear: " + btns.ToString() & _
        Microsoft.VisualBasic.ControlChars.Cr & "Count After Clear: " & _
End Sub

public void ClearMyToolBar()
    int btns;
    // Get the count before the Clear method is called.
    btns = toolBar1.Buttons.Count;
    MessageBox.Show("Count Before Clear: " + btns.ToString() +
                    "\nCount After Clear: " + toolBar1.Buttons.Count.ToString());

void ClearMyToolBar()
    int btns;
    // Get the count before the Clear method is called.
    btns = toolBar1->Buttons->Count;
    MessageBox::Show(String::Format( S"Count Before Clear: {0}\nCount After Clear: {1}",
       __box(btns), __box(toolBar1->Buttons->Count)));

[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.


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.ToolBarButtonCollection Class | ToolBar.ToolBarButtonCollection Members | System.Windows.Forms Namespace | Remove | ToolBarButton | Add | Item

© 2015 Microsoft