ToolBarButton ToolBarButton ToolBarButton ToolBarButton Class

定义

表示一个 Windows 工具栏按钮。Represents a Windows toolbar button. 尽管 ToolStripButton 替换并扩展了早期版本的 ToolBarButton 控件,但也可以选择保留 ToolBarButton 以备向后兼容性和将来使用。Although ToolStripButton replaces and extends the ToolBarButton control of previous versions, ToolBarButton is retained for both backward compatibility and future use if you choose.

public ref class ToolBarButton : System::ComponentModel::Component
public class ToolBarButton : System.ComponentModel.Component
type ToolBarButton = class
    inherit Component
Public Class ToolBarButton
Inherits Component
继承

示例

下面的代码示例创建一个ToolBar和三ToolBarButton个控件。The following code example creates a ToolBar and three ToolBarButton controls. 工具栏按钮将分配给按钮集合, 集合将分配给工具栏, 并将工具栏添加到窗体中。The toolbar buttons are assigned to the button collection, the collection is assigned to the toolbar, and the toolbar is added to the form. 在工具栏的Button ToolBarButtonClickEventArgs事件上, 计算的属性, 并打开适当的对话框。 ButtonClickOn the ButtonClick event of the toolbar, the Button property of the ToolBarButtonClickEventArgs is evaluated and the appropriate dialog box opened. 此代码要求Form已创建OpenFileDialogSaveFileDialog、和的PrintDialogThis code requires that a Form, an OpenFileDialog, a SaveFileDialog, and a PrintDialog have all been created.

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

注解

ToolBarButton控件是控件的ToolBar父级。ToolBarButton controls are parented by ToolBar controls. 创建工具栏按钮后要设置的通用属性为Text和。 ImageIndexCommon properties to set once the toolbar button has been created are Text and ImageIndex. 设置按钮的属性, 以在图像的下方或右侧显示文本。 TextSet the Text property of the button to display text beneath or to the right of the image. 若要通过创建ImageList将图像分配给按钮, 请将其分配给工具栏的ImageList属性, 然后将ImageIndex图像索引值分配给按钮的属性。To assign images to the buttons by creating an ImageList, assigning it to the ImageList property of the toolbar; then assign the image index value to the ImageIndex property of the button.

若要更改分配给工具栏的工具栏按钮的外观, 请设置Appearance父 toolbar 控件的属性。To change the appearance of the toolbar buttons assigned to the toolbar, set the Appearance property of the parent toolbar control. ToolBarAppearance.Flat外观为按钮提供平面外观。The ToolBarAppearance.Flat appearance gives the buttons a flat appearance. 当鼠标指针移到按钮上时, 其外观将变为三维。As the mouse pointer moves over the buttons, their appearance changes to three-dimensional. 当按钮具有平面外观时, 按钮分隔符显示为线条, 而不是按钮之间的空格。Button separators appear as lines rather than spaces between the buttons when the buttons have a flat appearance. ToolBarAppearance.Normal如果将Appearance属性设置为, 则按钮显示为凸起和三维, 分隔符显示为按钮之间的间隔。If the Appearance property is set to ToolBarAppearance.Normal, the buttons appear raised and three-dimensional, and the separators appear as a gap between the buttons.

如果将ContextMenu ToolBarButtonStyle.DropDown属性设置为, 则可以为该按钮指定。 StyleYou can assign a ContextMenu to a button if the Style property is set to ToolBarButtonStyle.DropDown. 单击该按钮时, 将显示分配的菜单。When the button is clicked, the assigned menu is displayed.

ToolBarButton若要创建要ToolBar在上显示的控件的集合, 请Buttons使用属性的Add方法分别添加按钮。To create a collection of ToolBarButton controls to display on a ToolBar, add the buttons individually by using the Add method of the Buttons property. 或者, 您可以使用AddRange方法添加多个工具栏按钮。Alternatively, you can add several toolbar buttons using the AddRange method.

构造函数

ToolBarButton() ToolBarButton() ToolBarButton() ToolBarButton()

初始化 ToolBarButton 类的新实例。Initializes a new instance of the ToolBarButton class.

ToolBarButton(String) ToolBarButton(String) ToolBarButton(String) ToolBarButton(String)

初始化 ToolBarButton 类的新实例,并在按钮上显示分配的文本。Initializes a new instance of the ToolBarButton class and displays the assigned text on the button.

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
DropDownMenu DropDownMenu DropDownMenu DropDownMenu

获取或设置要显示在下拉工具栏按钮中的菜单。Gets or sets the menu to be displayed in the drop-down toolbar button.

Enabled Enabled Enabled Enabled

获取或设置一个值,该值指示是否启用此按钮。Gets or sets a value indicating whether the button is enabled.

Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ImageIndex ImageIndex ImageIndex ImageIndex

获取或设置分配给按钮的图像的索引值。Gets or sets the index value of the image assigned to the button.

ImageKey ImageKey ImageKey ImageKey

获取或设置分配给此按钮的图像的名称。Gets or sets the name of the image assigned to the button.

Name Name Name Name

按钮的名称。The name of the button.

Parent Parent Parent Parent

获取向其分配工具栏按钮的工具栏控件。Gets the toolbar control that the toolbar button is assigned to.

PartialPush PartialPush PartialPush PartialPush

获取或设置一个值,该值指示切换式工具栏按钮是否为部分按下状态。Gets or sets a value indicating whether a toggle-style toolbar button is partially pushed.

Pushed Pushed Pushed Pushed

获取或设置一个值,该值指示切换式工具栏按钮当前是否处于按下状态。Gets or sets a value indicating whether a toggle-style toolbar button is currently in the pushed state.

Rectangle Rectangle Rectangle Rectangle

获取工具栏按钮的边框。Gets the bounding rectangle for a toolbar button.

Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Style Style Style Style

获取或设置工具栏按钮的样式。Gets or sets the style of the toolbar button.

Tag Tag Tag Tag

获取或设置包含有关工具栏按钮的数据的对象。Gets or sets the object that contains data about the toolbar button.

Text Text Text Text

获取或设置显示在工具栏按钮上的文本。Gets or sets the text displayed on the toolbar button.

ToolTipText ToolTipText ToolTipText ToolTipText

获取或设置显示为该按钮的工具提示的文本。Gets or sets the text that appears as a ToolTip for the button.

Visible Visible Visible Visible

获取或设置一个值,该值指示工具栏按钮是否可见。Gets or sets a value indicating whether the toolbar button is visible.

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 ToolBarButton 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the ToolBarButton and optionally releases the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

返回表示 ToolBarButton 控件的字符串。Returns a string that represents the ToolBarButton control.

事件

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

适用于

另请参阅