Share via


ToolBar.ToolBarButtonCollection.Add Método

Definición

Agrega un nuevo botón de barra de herramientas al final de la colección de botones de barra de herramientas.

Sobrecargas

Add(String)

Agrega un nuevo botón de barra de herramientas al final de la colección de botones de barra de herramientas con el valor de la propiedad Text especificado.

Add(ToolBarButton)

Agrega el botón de barra de herramientas especificado al final de la colección de botones de barra de herramientas.

Add(String)

Agrega un nuevo botón de barra de herramientas al final de la colección de botones de barra de herramientas con el valor de la propiedad Text especificado.

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

Parámetros

text
String

Texto que se va a mostrar en el nuevo ToolBarButton.

Devoluciones

Int32

Valor de índice de base cero del ToolBarButton agregado a la colección.

Ejemplos

En el ejemplo de código siguiente se quita un existente ToolBarButton de un ToolBar control si existe y se agregan e insertan cuatro objetos nuevos ToolBarButton en .ToolBar En este ejemplo se requiere que tenga un Form con un ToolBar control en él.

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

Comentarios

También puede agregar nuevos ToolBarButton objetos a la colección mediante los AddRange métodos o Insert , o la otra versión del Add método .

Para quitar un ToolBarButton objeto que ha agregado anteriormente, use los Removemétodos , RemoveAt o Clear .

Consulte también

Se aplica a

Add(ToolBarButton)

Agrega el botón de barra de herramientas especificado al final de la colección de botones de barra de herramientas.

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

Parámetros

button
ToolBarButton

ToolBarButton que se va a agregar al final de todos los botones existentes.

Devoluciones

Int32

Valor de índice de base cero del ToolBarButton agregado a la colección.

Ejemplos

En el ejemplo de código siguiente se agrega un nuevo ToolBarButton control a un existente ToolBar con botones existentes. El botón de la barra de herramientas se agregará al final de la ToolBar.Buttons colección.

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

Comentarios

También puede agregar nuevos ToolBarButton objetos a la colección mediante los AddRange métodos o Insert , o la otra versión del Add método .

Para quitar un ToolBarButton objeto que ha agregado anteriormente, use los Removemétodos , RemoveAt o Clear .

Consulte también

Se aplica a