ToolBar.ToolBarButtonCollection.Add Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Adiciona um novo botão de barra de ferramentas ao final da coleção de botões de barra de ferramentas.
Sobrecargas
| Add(String) |
Adiciona um novo botão de barra de ferramentas ao final da coleção de botões de barra de ferramentas com o valor da propriedade Text especificado. |
| Add(ToolBarButton) |
Adiciona o botão de barra de ferramentas especificado ao final da coleção de botões de barra de ferramentas. |
Add(String)
Adiciona um novo botão de barra de ferramentas ao final da coleção de botões de barra de ferramentas com o valor da propriedade 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
O texto a ser exibido no novo ToolBarButton.
Retornos
O valor de índice baseado em zero do ToolBarButton adicionado à coleção.
Exemplos
O exemplo de código a seguir remove um existente ToolBarButton de um ToolBar controle se ele existir e adiciona e insere quatro novos ToolBarButton objetos ao ToolBar. Este exemplo exige que você tenha um Form ToolBar controle sobre ele.
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
Comentários
Você também pode adicionar novos ToolBarButton objetos à coleção usando os métodos ou Insert métodos AddRange ou a outra versão do Add método.
Para remover um ToolBarButton que você adicionou anteriormente, use os Removemétodos ou Clear os RemoveAt métodos.
Confira também
Aplica-se a
Add(ToolBarButton)
Adiciona o botão de barra de ferramentas especificado ao final da coleção de botões de barra de ferramentas.
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
O ToolBarButton a ser adicionado após todos os botões existentes.
Retornos
O valor de índice baseado em zero do ToolBarButton adicionado à coleção.
Exemplos
O exemplo de código a seguir adiciona um novo ToolBarButton controle a um existente ToolBar com botões existentes. O botão da barra de ferramentas será adicionado ao final da ToolBar.Buttons coleção.
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
Comentários
Você também pode adicionar novos ToolBarButton objetos à coleção usando os métodos ou Insert métodos AddRange ou a outra versão do Add método.
Para remover um ToolBarButton que você adicionou anteriormente, use os Removemétodos ou Clear os RemoveAt métodos.