ToolBar.ToolBarButtonCollection.Clear 方法

定义

从工具栏按钮集合中移除所有按钮。

public:
 virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

实现

示例

下面的代码示例显示 Count 调用方法前后的 Buttons 前面和之后 Clear 。 此代码要求 ToolBar 已创建至少一个 ToolBarButton 代码。

public:
   void ClearMyToolBar()
   {
      int btns;
      // Get the count before the Clear method is called.
      btns = toolBar1->Buttons->Count;
      toolBar1->Buttons->Clear();
      MessageBox::Show( "Count Before Clear: " + btns.ToString() +
         "\nCount After Clear: " + toolBar1->Buttons->Count.ToString() );
   }
public void ClearMyToolBar()
 {
    int btns;
    // Get the count before the Clear method is called.
    btns = toolBar1.Buttons.Count;
    toolBar1.Buttons.Clear();
    MessageBox.Show("Count Before Clear: " + btns.ToString() +
                    "\nCount After Clear: " + toolBar1.Buttons.Count.ToString());
 }
Public Sub ClearMyToolBar()
    Dim btns As Integer
    ' Get the count before the Clear method is called.
    btns = toolBar1.Buttons.Count
    toolBar1.Buttons.Clear()
    MessageBox.Show("Count Before Clear: " + btns.ToString() & _
        Microsoft.VisualBasic.ControlChars.Cr & "Count After Clear: " & _
        toolBar1.Buttons.Count.ToString())
End Sub

注解

该方法 Clear 循环访问集合并删除分配给该 ToolBar.ToolBarButtonCollection集合的所有工具栏按钮。

若要从集合中删除单个工具栏按钮,请使用 RemoveRemoveAt 方法。

若要向集合添加新ToolBarButton对象,请使用AddAddRangeInsert方法。

适用于

另请参阅