共用方式為


ToolBar.ToolBarButtonCollection.Clear 方法

定義

將所有按鈕從工具列按鈕集合中移除。

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

實作

範例

下列程式碼範例會顯示呼叫 Count 方法前後的 ButtonsClear 。 此程式碼需要 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 方法。

適用於

另請參閱