ToolBar.ToolBarButtonCollection.AddRange(ToolBarButton[]) 메서드

정의

이 도구 모음 단추 컬렉션에 도구 모음 단추의 컬렉션을 추가합니다.

public:
 void AddRange(cli::array <System::Windows::Forms::ToolBarButton ^> ^ buttons);
public void AddRange (System.Windows.Forms.ToolBarButton[] buttons);
member this.AddRange : System.Windows.Forms.ToolBarButton[] -> unit
Public Sub AddRange (buttons As ToolBarButton())

매개 변수

buttons
ToolBarButton[]

배열에 포함된 이 ToolBarButton에 추가할 ToolBar.ToolBarButtonCollection 컨트롤의 컬렉션입니다.

예제

다음 코드 예제에서는 존재하는 경우 컨트롤에서 기존 개체를 ToolBar ToolBarButton 제거하고 4개의 새 ToolBarButton 개체를 ToolBar추가하고 삽입합니다. 이 예제에서는 컨트롤이 Form ToolBar 있어야 합니다.

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

설명

ToolBarButton 배열에 nodes 포함된 개체는 컬렉션의 끝에 추가됩니다.

메서드를 사용하여 컬렉션에 각각 ToolBarButton 을 수동으로 추가하는 대신 이전에 만든 ToolBarButton 개체 그룹을 컬렉션 Add 에 빠르게 추가할 수 있습니다.

이전에 추가한 ToolBarButton 항목을 제거하려면 또는 RemoveAt Clear 메서드를 Remove사용합니다.

적용 대상

추가 정보