다음을 통해 공유


ToolBar.ToolBarButtonCollection.Contains(ToolBarButton) 메서드

정의

지정된 도구 모음 단추가 컬렉션의 멤버인지 확인합니다.

public:
 bool Contains(System::Windows::Forms::ToolBarButton ^ button);
public bool Contains (System.Windows.Forms.ToolBarButton button);
member this.Contains : System.Windows.Forms.ToolBarButton -> bool
Public Function Contains (button As ToolBarButton) As Boolean

매개 변수

button
ToolBarButton

컬렉션에서 찾을 ToolBarButton입니다.

반환

Boolean

ToolBarButton이 컬렉션의 멤버이면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 존재하는 경우 컨트롤에서 기존 개체를 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작업을 수행하기 전에 컬렉션의 멤버인지 여부를 ToolBarButton 확인할 수 있습니다. 이 메서드를 사용하여 컬렉션에 ToolBarButton 추가되었거나 여전히 컬렉션의 멤버인지 확인할 수 있습니다.

적용 대상