ToolBar.ToolBarButtonCollection.Add Metoda

Definice

Přidá nové tlačítko panelu nástrojů na konec kolekce tlačítek panelu nástrojů.

Přetížení

Add(String)

Přidá nové tlačítko panelu nástrojů na konec kolekce tlačítek panelu nástrojů se zadanou Text hodnotou vlastnosti.

Add(ToolBarButton)

Přidá zadané tlačítko panelu nástrojů na konec kolekce tlačítek panelu nástrojů.

Add(String)

Přidá nové tlačítko panelu nástrojů na konec kolekce tlačítek panelu nástrojů se zadanou Text hodnotou vlastnosti.

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

Parametry

text
String

Text, který se má zobrazit na novém ToolBarButton.

Návraty

Int32

Nulová hodnota indexu ToolBarButton přidaného do kolekce.

Příklady

Následující příklad kódu odebere existující ToolBarButton z ToolBar ovládacího prvku, pokud existuje a přidá a vloží čtyři nové ToolBarButton objekty do ToolBar. Tento příklad vyžaduje, abyste na něm měli Form ovládací ToolBar prvek.

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

Poznámky

Do kolekce můžete také přidat nové ToolBarButton objekty pomocí AddRange metod nebo Insert metod nebo jiné verze Add metody.

Chcete-li odebrat dříve přidanou ToolBarButton verzi, použijte příkazy Removenebo RemoveAt Clear metody.

Viz také

Platí pro

Add(ToolBarButton)

Přidá zadané tlačítko panelu nástrojů na konec kolekce tlačítek panelu nástrojů.

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

Parametry

button
ToolBarButton

Po ToolBarButton všech existujících tlačítkách se má přidat.

Návraty

Int32

Nulová hodnota indexu ToolBarButton přidaného do kolekce.

Příklady

Následující příklad kódu přidá nový ToolBarButton ovládací prvek do existujícího ToolBar s existujícími tlačítky. Tlačítko panelu nástrojů se přidá na konec ToolBar.Buttons kolekce.

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

Poznámky

Do kolekce můžete také přidat nové ToolBarButton objekty pomocí AddRange metod nebo Insert metod nebo jiné verze Add metody.

Chcete-li odebrat dříve přidanou ToolBarButton verzi, použijte příkazy Removenebo RemoveAt Clear metody.

Viz také

Platí pro