ToolBarButtonClickEventArgs 类

定义

ButtonClick 事件提供数据。

public ref class ToolBarButtonClickEventArgs : EventArgs
public class ToolBarButtonClickEventArgs : EventArgs
type ToolBarButtonClickEventArgs = class
    inherit EventArgs
Public Class ToolBarButtonClickEventArgs
Inherits EventArgs
继承
ToolBarButtonClickEventArgs

示例

以下示例实例化 一个 和三个 ToolBarToolBarButton 控件。 工具栏按钮分配给按钮集合,集合分配给工具栏,工具栏添加到窗体。 在 ButtonClick 工具栏的 事件中 Button ,计算 的 ToolBarButtonClickEventArgs 属性,并打开相应的对话框。 此代码假定 Form、、OpenFileDialogSaveFileDialog、 和 PrintDialog 已实例化。

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.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 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

注解

每当用户单击控件上的 ToolBar 按钮时,将发生该事件。 属性 Button 包含 ToolBarButton 与单击的按钮有关的信息的 。

构造函数

ToolBarButtonClickEventArgs(ToolBarButton)

初始化 ToolBarButtonClickEventArgs 类的新实例。

属性

Button

获取或设置被单击的 ToolBarButton

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅