ToolBar.ToolBarButtonCollection.Add Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Ajoute un nouveau bouton de barre d’outils à la fin de la collection de boutons de barre d’outils.
Surcharges
| Nom | Description |
|---|---|
| Add(String) |
Ajoute un nouveau bouton de barre d’outils à la fin de la collection de boutons de barre d’outils avec la valeur de propriété spécifiée Text . |
| Add(ToolBarButton) |
Ajoute le bouton de barre d’outils spécifié à la fin de la collection de boutons de barre d’outils. |
Add(String)
Ajoute un nouveau bouton de barre d’outils à la fin de la collection de boutons de barre d’outils avec la valeur de propriété spécifiée 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
Paramètres
- text
- String
Texte à afficher sur le nouveau ToolBarButton.
Retours
Valeur d’index de base zéro de l’élément ToolBarButton ajouté à la collection.
Exemples
L’exemple de ToolBarButton code suivant supprime un contrôle existant ToolBar s’il existe et ajoute et insère quatre nouveaux ToolBarButton objets à l’objet ToolBar. Cet exemple nécessite que vous disposiez d’un FormToolBar contrôle dessus.
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
Remarques
Vous pouvez également ajouter de nouveaux ToolBarButton objets à la collection à l’aide des méthodes ou AddRange de l’autre Insert version de la Add méthode.
Pour supprimer un ToolBarButton élément que vous avez précédemment ajouté, utilisez le ou RemoveRemoveAt les Clearméthodes.
Voir aussi
S’applique à
Add(ToolBarButton)
Ajoute le bouton de barre d’outils spécifié à la fin de la collection de boutons de barre d’outils.
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
Paramètres
- button
- ToolBarButton
ToolBarButton À ajouter après tous les boutons existants.
Retours
Valeur d’index de base zéro de l’élément ToolBarButton ajouté à la collection.
Exemples
L’exemple de code suivant ajoute un nouveau ToolBarButton contrôle à un contrôle existant ToolBar avec des boutons existants. Le bouton de barre d’outils est ajouté à la fin de la ToolBar.Buttons collection.
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
Remarques
Vous pouvez également ajouter de nouveaux ToolBarButton objets à la collection à l’aide des méthodes ou AddRange de l’autre Insert version de la Add méthode.
Pour supprimer un ToolBarButton élément que vous avez précédemment ajouté, utilisez le ou RemoveRemoveAt les Clearméthodes.