ToolBar.ToolBarButtonCollection.Add Methode

Definition

Fügt eine neue Symbolleisten-Schaltfläche am Ende der Auflistung der Symbolleisten-Schaltflächen hinzu.

Überlädt

Add(String)

Fügt am Ende der Auflistung der Symbolleisten-Schaltflächen eine neue Symbolleisten-Schaltfläche mit dem angegebenen Text-Eigenschaftswert hinzu.

Add(ToolBarButton)

Fügt die angegebene Symbolleisten-Schaltfläche am Ende der Auflistung der Symbolleisten-Schaltflächen hinzu.

Add(String)

Fügt am Ende der Auflistung der Symbolleisten-Schaltflächen eine neue Symbolleisten-Schaltfläche mit dem angegebenen Text-Eigenschaftswert hinzu.

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

Parameter

text
String

Der auf dem neuen ToolBarButton anzuzeigende Text.

Gibt zurück

Int32

Der nullbasierte Indexwert des ToolBarButton, das der Auflistung hinzugefügt wird.

Beispiele

Im folgenden Codebeispiel wird ein vorhandenes ToolBarButton ToolBar Steuerelement entfernt, wenn es vorhanden ist, und fügt vier neue ToolBarButton Objekte in das ToolBarElement ein. In diesem Beispiel ist erforderlich, dass Sie über ein Form ToolBar Steuerelement verfügen.

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

Hinweise

Sie können auch neue ToolBarButton Objekte zur Auflistung hinzufügen, indem Sie die AddRange Insert Methoden oder die andere Version der Add Methode verwenden.

Verwenden Sie zum Entfernen eines ToolBarButton zuvor hinzugefügten Typs die RemoveRemoveAt Methoden oder Clear Methoden.

Siehe auch

Gilt für

Add(ToolBarButton)

Fügt die angegebene Symbolleisten-Schaltfläche am Ende der Auflistung der Symbolleisten-Schaltflächen hinzu.

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

Parameter

button
ToolBarButton

Der ToolBarButton, der nach sämtlichen vorhandenen Schaltflächen hinzugefügt werden soll.

Gibt zurück

Int32

Der nullbasierte Indexwert des ToolBarButton, das der Auflistung hinzugefügt wird.

Beispiele

Im folgenden Codebeispiel wird einem vorhandenen ToolBar mit vorhandenen Schaltflächen ein neues ToolBarButton Steuerelement hinzugefügt. Die Symbolleistenschaltfläche wird am Ende der ToolBar.Buttons Auflistung hinzugefügt.

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

Hinweise

Sie können auch neue ToolBarButton Objekte zur Auflistung hinzufügen, indem Sie die AddRange Insert Methoden oder die andere Version der Add Methode verwenden.

Verwenden Sie zum Entfernen eines ToolBarButton zuvor hinzugefügten Typs die RemoveRemoveAt Methoden oder Clear Methoden.

Siehe auch

Gilt für