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부터 시작) 값입니다.

예제

다음 코드 예제에서는 존재하는 경우 컨트롤에서 기존 개체를 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

설명

또는 메서드 또는 Insert 메서드의 다른 버전을 Add 사용하여 AddRange 컬렉션에 새 ToolBarButton 개체를 추가할 수도 있습니다.

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

추가 정보

적용 대상

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

설명

또는 메서드 또는 Insert 메서드의 다른 버전을 Add 사용하여 AddRange 컬렉션에 새 ToolBarButton 개체를 추가할 수도 있습니다.

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

추가 정보

적용 대상