ToolBar.ToolBarButtonCollection.Add メソッド

定義

新しいツール バー ボタンをツール バー ボタン コレクションの末尾に追加します。

オーバーロード

Add(String)

新しいツール バー ボタンを指定された Text プロパティの値を持つツール バー ボタン コレクションの末尾に追加します。

Add(ToolBarButton)

指定されたツール バー ボタンをツール バー ボタン コレクションの末尾に追加します。

Add(String)

新しいツール バー ボタンを指定された 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

パラメーター

text
String

新しい ToolBarButton に表示されるテキスト。

戻り値

Int32

コレクションに追加された ToolBarButton の 0 から始まるインデックス値。

次のコード例では、既存 ToolBarButton のオブジェクトが存在する場合はコントロールから ToolBar 削除し、4 つの新しい ToolBarButton オブジェクトを追加して ToolBar挿入します。 この例では、コントロールを持っているFormToolBar必要があります。

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

注釈

メソッドまたはその他のバージョンのメソッドを使用して、コレクションにInsertAddRange新しいToolBarButtonオブジェクトをAdd追加することもできます。

以前に追加したファイルを削除ToolBarButtonするには、次のメソッドRemoveAtRemoveClear使用します。

こちらもご覧ください

適用対象

Add(ToolBarButton)

指定されたツール バー ボタンをツール バー ボタン コレクションの末尾に追加します。

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

パラメーター

button
ToolBarButton

すべての既存のボタンの後に追加される ToolBarButton

戻り値

Int32

コレクションに追加された ToolBarButton の 0 から始まるインデックス値。

次のコード例では、既存のボタンを持つ既存ToolBarのコントロールに新しいToolBarButtonコントロールを追加します。 ツール バー ボタンがコレクションの末尾に ToolBar.Buttons 追加されます。

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

注釈

メソッドまたはその他のバージョンのメソッドを使用して、コレクションにInsertAddRange新しいToolBarButtonオブジェクトをAdd追加することもできます。

以前に追加したファイルを削除ToolBarButtonするには、次のメソッドRemoveAtRemoveClear使用します。

こちらもご覧ください

適用対象