다음을 통해 공유


ToolBarButton 클래스

Windows 도구 모음 단추를 나타냅니다. ToolStripButton에 의해 이전 버전의 ToolBarButton 컨트롤이 교체되고 확장되었지만 ToolBarButton은 이전 버전과의 호환성 및 앞으로의 사용 가능성을 고려하여 유지됩니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Class ToolBarButton
    Inherits Component
‘사용 방법
Dim instance As ToolBarButton
public class ToolBarButton : Component
public ref class ToolBarButton : public Component
public class ToolBarButton extends Component
public class ToolBarButton extends Component

설명

ToolBarButton 컨트롤은 ToolBar 컨트롤의 자식 컨트롤입니다. 도구 모음 단추가 만들어진 다음에 설정되는 공용 속성은 TextImageIndex입니다. 텍스트를 이미지 아래 또는 오른쪽에 표시하도록 단추의 Text 속성을 설정합니다. ImageList를 만든 후 도구 모음의 ImageList 속성에 할당하는 방법으로 단추에 이미지를 할당하려면 이미지 인덱스 값을 단추의 ImageIndex 속성에 할당합니다.

도구 모음에 할당되는 도구 모음 단추의 모양을 변경하려면 부모 ToolBar 컨트롤의 Appearance 속성을 설정합니다. ToolBarAppearance.Flat 모양을 사용하면 단추의 모양을 평면으로 만들 수 있습니다. 마우스 포인터를 단추 위로 가져가면 단추의 모양이 3차원으로 바뀝니다. 단추 구분선은 도구 모음이 평면 모양일 때 단추 사이에 공간이 아닌 선으로 나타납니다. Appearance 속성이 ToolBarAppearance.Normal로 설정된 경우에는 단추가 3차원의 볼록한 모양으로 표시되고 단추 사이의 간격으로 구분선이 표시됩니다.

Style 속성이 ToolBarButtonStyle.DropDown으로 설정된 경우에는 단추에 ContextMenu을 할당할 수 있습니다. 이 경우 해당 단추를 클릭하면 할당된 메뉴가 표시됩니다.

ToolBar에 표시할 ToolBarButton 컨트롤의 컬렉션을 만들려면 Buttons 속성의 Add 메서드를 사용하여 각 단추를 개별적으로 추가합니다. 또는 AddRange 메서드를 사용하여 여러 도구 모음 단추를 추가할 수 있습니다.

예제

다음 코드 예제에서는 ToolBar와 세 가지 ToolBarButton 컨트롤을 만듭니다. 도구 모음 단추는 단추 컬렉션에 할당되고, 이 컬렉션은 도구 모음에 할당되며, 도구 모음은 폼에 추가됩니다. 도구 모음의 ButtonClick 이벤트에서는 ToolBarButtonClickEventArgsButton 속성이 확인되고 해당 대화 상자가 열립니다. 이 코드를 실행하려면 Form, OpenFileDialog, SaveFileDialogPrintDialog를 모두 만들어야 합니다.

Public Sub InitializeMyToolBar()
    ' Create and initialize the ToolBar and ToolBarButton controls.
    Dim toolBar1 As New ToolBar()
    Dim toolBarButton1 As New ToolBarButton()
    Dim toolBarButton2 As New ToolBarButton()
    Dim toolBarButton3 As New ToolBarButton()
    
    ' Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open"
    toolBarButton2.Text = "Save"
    toolBarButton3.Text = "Print"
    
    ' Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1)
    toolBar1.Buttons.Add(toolBarButton2)
    toolBar1.Buttons.Add(toolBarButton3)
    
    ' Add the event-handler delegate.
    AddHandler toolBar1.ButtonClick, AddressOf Me.toolBar1_ButtonClick
    
    ' Add the ToolBar to the Form.
    Controls.Add(toolBar1)
End Sub    

Private Sub toolBar1_ButtonClick(ByVal sender As Object, _
ByVal e As ToolBarButtonClickEventArgs)

    ' Evaluate the Button property to determine which button was clicked.
    Select Case toolBar1.Buttons.IndexOf(e.Button)
        Case 0
            openFileDialog1.ShowDialog()
            ' Insert code to open the file.
        Case 1
            saveFileDialog1.ShowDialog()
            ' Insert code to save the file.
        Case 2
            printDialog1.ShowDialog()
            ' Insert code to print the file.
    End Select
End Sub
public void InitializeMyToolBar()
 {
    // Create and initialize the ToolBar and ToolBarButton controls.
    toolBar1 = new ToolBar();
    ToolBarButton toolBarButton1 = new ToolBarButton();
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();
 
    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open";
    toolBarButton2.Text = "Save";
    toolBarButton3.Text = "Print";
 
    // Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1);
    toolBar1.Buttons.Add(toolBarButton2);
    toolBar1.Buttons.Add(toolBarButton3);
    
    // Add the event-handler delegate.
    toolBar1.ButtonClick += new ToolBarButtonClickEventHandler (
       this.toolBar1_ButtonClick);
    
    // Add the ToolBar to the Form.
    Controls.Add(toolBar1);
 }
 
 private void toolBar1_ButtonClick (
                         Object sender, 
                         ToolBarButtonClickEventArgs e)
 {
   // Evaluate the Button property to determine which button was clicked.
   switch(toolBar1.Buttons.IndexOf(e.Button))
   {
      case 0:
         openFileDialog1.ShowDialog();
         // Insert code to open the file.
         break; 
      case 1:
         saveFileDialog1.ShowDialog();
         // Insert code to save the file.
         break; 
      case 2:
         printDialog1.ShowDialog();
         // Insert code to print the file.    
         break; 
    }
 }
public:
   void InitializeMyToolBar()
   {
      // Create and initialize the ToolBar and ToolBarButton controls.
      toolBar1 = gcnew ToolBar;
      ToolBarButton^ toolBarButton1 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton3 = gcnew ToolBarButton;
      
      // Set the Text properties of the ToolBarButton controls.
      toolBarButton1->Text = "Open";
      toolBarButton2->Text = "Save";
      toolBarButton3->Text = "Print";
      
      // Add the ToolBarButton controls to the ToolBar.
      toolBar1->Buttons->Add( toolBarButton1 );
      toolBar1->Buttons->Add( toolBarButton2 );
      toolBar1->Buttons->Add( toolBarButton3 );
      
      // Add the event-handler delegate.
      toolBar1->ButtonClick += gcnew ToolBarButtonClickEventHandler(
         this, &Form1::toolBar1_ButtonClick );
      
      // Add the ToolBar to the Form.
      Controls->Add( toolBar1 );
   }

private:
   void toolBar1_ButtonClick(
      Object^ sender,
      ToolBarButtonClickEventArgs^ e )
   {
      // Evaluate the Button property to determine which button was clicked.
      switch ( toolBar1->Buttons->IndexOf( e->Button ) )
      {
         case 0:
            openFileDialog1->ShowDialog();
            // Insert code to open the file.
            break;
         case 1:
            saveFileDialog1->ShowDialog();
            // Insert code to save the file.
            break;
         case 2:
            printDialog1->ShowDialog();
            // Insert code to print the file.    
            break;
      }
   }
public void InitializeMyToolBar()
{
    // Create and initialize the ToolBar and ToolBarButton controls.
    toolBar1 = new ToolBar();
    ToolBarButton toolBarButton1 = new ToolBarButton();
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();

    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1.set_Text("Open");
    toolBarButton2.set_Text("Save");
    toolBarButton3.set_Text("Print");

    // Add the ToolBarButton controls to the ToolBar.
    toolBar1.get_Buttons().Add(toolBarButton1);
    toolBar1.get_Buttons().Add(toolBarButton2);
    toolBar1.get_Buttons().Add(toolBarButton3);

    // Add the event-handler delegate.
    toolBar1.add_ButtonClick(new ToolBarButtonClickEventHandler(
                                 this.toolBar1_ButtonClick));

    // Add the ToolBar to the Form.
    get_Controls().Add(toolBar1);
} //InitializeMyToolBar

protected void toolBar1_ButtonClick(Object sender,
                                    ToolBarButtonClickEventArgs e)
{
    // Evaluate the Button property to determine which button was clicked.
    switch (toolBar1.get_Buttons().IndexOf(e.get_Button())) {
        case 0 :
            openFileDialog1.ShowDialog();
            // Insert code to open the file.
            break;
        case 1 :
            saveFileDialog1.ShowDialog();
            // Insert code to save the file.
            break;
        case 2 :
            printDialog1.ShowDialog();
            // Insert code to print the file.    
            break;
    } 
} //toolBar1_ButtonClick

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      System.Windows.Forms.ToolBarButton

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

ToolBarButton 멤버
System.Windows.Forms 네임스페이스
ToolBar 클래스
MenuItem 클래스
ImageList 클래스
ToolTip