ToolBar.ToolBarButtonCollection.Add 메서드

정의

도구 모음 단추 컬렉션의 끝에 새 도구 모음 단추를 추가합니다.

오버로드

Name Description
Add(String)

지정된 Text 속성 값을 사용하여 도구 모음 단추 컬렉션의 끝에 새 도구 모음 단추를 추가합니다.

Add(ToolBarButton)

지정된 도구 모음 단추를 도구 모음 단추 컬렉션의 끝에 추가합니다.

Add(String)

Source:
ToolBar.ToolBarButtonCollection.cs
Source:
ToolBar.ToolBarButtonCollection.cs

지정된 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에 표시할 텍스트입니다.

반품

컬렉션에 추가된 인덱스 값( 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

설명

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

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

추가 정보

적용 대상

Add(ToolBarButton)

Source:
ToolBar.ToolBarButtonCollection.cs
Source:
ToolBar.ToolBarButtonCollection.cs

지정된 도구 모음 단추를 도구 모음 단추 컬렉션의 끝에 추가합니다.

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 모든 기존 단추 후에 추가할 항목입니다.

반품

컬렉션에 추가된 인덱스 값( ToolBarButton 0부터 시작)입니다.

예제

다음 코드 예제에서는 기존 단추를 사용하여 기존 ToolBarButton 컨트롤에 새 ToolBar 컨트롤을 추가합니다. 도구 모음 단추가 컬렉션의 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

설명

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

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

추가 정보

적용 대상