語言

ToolBar.ToolBarButtonCollection.Add 方法

定義

在工具列按鈕集合的末尾新增了一個工具列按鈕。

多載

名稱 Description
Add(String)

在工具列按鈕集合末端新增一個工具列按鈕,並帶有指定的 Text 屬性值。

Add(ToolBarButton)

將指定的工具列按鈕加入工具列按鈕集合的末尾。

Add(String)

來源:
ToolBar.ToolBarButtonCollection.cs
來源:
ToolBar.ToolBarButtonCollection.cs

在工具列按鈕集合末端新增一個工具列按鈕,並帶有指定的 Text 屬性值。

public:
 int Add(System::String ^ text);
public int Add(string text);
member this.Add : string -> int
Public Function Add (text As String) As Integer

參數

text
String

文字將顯示在新的 ToolBarButton.

傳回

為 加到集合的 的零基索引值 ToolBarButton 。

範例

以下程式碼範例若控制項存在,則移除ToolBarButtonToolBar該控制項,並新增四個新ToolBarButton物件。ToolBar 這個例子需要你有一個 Form 控制 ToolBar 點。

void AddToolbarButtons( ToolBar^ toolBar )
{
   if (  !toolBar->Buttons->IsReadOnly )
   {
      
      // If toolBarButton1 in in the collection, remove it.
      if ( toolBar->Buttons->Contains( toolBarButton1 ) )
      {
         toolBar->Buttons->Remove( toolBarButton1 );
      }
      
      // Create three toolbar buttons.
      ToolBarButton^ tbb1 = gcnew ToolBarButton( "tbb1" );
      ToolBarButton^ tbb2 = gcnew ToolBarButton( "tbb2" );
      ToolBarButton^ tbb3 = gcnew ToolBarButton( "tbb3" );
      
      // Add toolbar buttons to the toolbar.
      array<ToolBarButton^>^buttons = {tbb2,tbb3};
      toolBar->Buttons->AddRange( buttons );
      toolBar->Buttons->Add( "tbb4" );
      
      // Insert tbb1 into the first position in the collection.
      toolBar->Buttons->Insert( 0, tbb1 );
   }
}
private void AddToolbarButtons(ToolBar toolBar)
{
   if(!toolBar.Buttons.IsReadOnly)
   {
      // If toolBarButton1 in in the collection, remove it.
      if(toolBar.Buttons.Contains(toolBarButton1))
      {
         toolBar.Buttons.Remove(toolBarButton1);
      }
    
      // Create three toolbar buttons.
      ToolBarButton tbb1 = new ToolBarButton("tbb1");
      ToolBarButton tbb2 = new ToolBarButton("tbb2");
      ToolBarButton tbb3 = new ToolBarButton("tbb3");
      
      // Add toolbar buttons to the toolbar.		
      toolBar.Buttons.AddRange(new ToolBarButton[] {tbb2, tbb3});
      toolBar.Buttons.Add("tbb4");
    
      // Insert tbb1 into the first position in the collection.
      toolBar.Buttons.Insert(0, tbb1);
   }
}
Private Sub AddToolbarButtons(toolBar As ToolBar)
   If Not toolBar.Buttons.IsReadOnly Then
      ' If toolBarButton1 in in the collection, remove it.
      If toolBar.Buttons.Contains(toolBarButton1) Then
         toolBar.Buttons.Remove(toolBarButton1)
      End If

      ' Create three toolbar buttons.
      Dim tbb1 As New ToolBarButton("tbb1")
      Dim tbb2 As New ToolBarButton("tbb2")
      Dim tbb3 As New ToolBarButton("tbb3")

      ' Add toolbar buttons to the toolbar.		
      toolBar.Buttons.AddRange(New ToolBarButton() {tbb2, tbb3})
      toolBar.Buttons.Add("tbb4")

      ' Insert tbb1 into the first position in the collection.
      toolBar.Buttons.Insert(0, tbb1)
   End If
End Sub

備註

你也可以透過使用 ToolBarButton or AddRange 方法或該方法的其他Insert版本,將新Add物件加入集合。

要移除你之前加的 , ToolBarButton 請使用 Remove方法 RemoveAtClear 。

另請參閱

適用於

Add(ToolBarButton)

來源:
ToolBar.ToolBarButtonCollection.cs
來源:
ToolBar.ToolBarButtonCollection.cs

將指定的工具列按鈕加入工具列按鈕集合的末尾。

public:
 int Add(System::Windows::Forms::ToolBarButton ^ button);
public int Add(System.Windows.Forms.ToolBarButton button);
member this.Add : System.Windows.Forms.ToolBarButton -> int
Public Function Add (button As ToolBarButton) As Integer

參數

button
ToolBarButton

ToolBarButton這些按鈕會在所有現有按鈕之後加入。

傳回

為 加到集合的 的零基索引值 ToolBarButton 。

範例

以下程式碼範例是在 ToolBarButton 已有按鈕的現有 ToolBar 控制項上新增一個控制項。 工具列按鈕會被加在集合的 ToolBar.Buttons 最後。

public:
   void AddMyButton()
   {
      ToolBarButton^ toolBarButton1 = gcnew ToolBarButton;
      toolBarButton1->Text = "Print";
      
      // Add the new toolbar button to the toolbar.
      toolBar1->Buttons->Add( toolBarButton1 );
   }
public void AddMyButton()
 {
    ToolBarButton toolBarButton1 = new ToolBarButton();
    toolBarButton1.Text = "Print";
 
    // Add the new toolbar button to the toolbar.
    toolBar1.Buttons.Add(toolBarButton1);
 }
Public Sub AddMyButton()
    Dim toolBarButton1 As New ToolBarButton()
    toolBarButton1.Text = "Print"
    
    ' Add the new toolbar button to the toolbar.
    toolBar1.Buttons.Add(toolBarButton1)
End Sub

備註

你也可以透過使用 ToolBarButton or AddRange 方法或該方法的其他Insert版本,將新Add物件加入集合。

要移除你之前加的 , ToolBarButton 請使用 Remove方法 RemoveAtClear 。

另請參閱

適用於