ToolStripItem.Click 事件


在单击 ToolStripItem 时发生。Occurs when the ToolStripItem is clicked.

 event EventHandler ^ Click;
public event EventHandler Click;
member this.Click : EventHandler 
Public Custom Event Click As EventHandler 


下面的代码示例演示如何设置 TextOverflowTextDirection 属性,以及如何处理 Click 事件。The following code example demonstrates how to set the Text, Overflow, and TextDirection properties, and handle the Click event. 若要运行此示例,请将以下代码粘贴到包含名为 movingToolStripToolStrip 的窗体中,并在窗体的构造函数或 Load 事件处理程序中调用 InitializeMovingToolStripTo run this example, paste the following code into a form that contains a ToolStrip named movingToolStrip and call InitializeMovingToolStrip in the form's constructor or Load event handler.

ToolStripButton^ changeDirectionButton;

void InitializeMovingToolStrip()
    changeDirectionButton = gcnew ToolStripButton;
    movingToolStrip->AutoSize = true;
    movingToolStrip->RenderMode = ToolStripRenderMode::System;
    changeDirectionButton->TextDirection = 
    changeDirectionButton->Overflow = 
    changeDirectionButton->Text = "Change Alignment";
    changeDirectionButton->Click += gcnew EventHandler(this, 

void changeDirectionButtonClick(Object^ sender, EventArgs^ e)
    ToolStripItem^ item = (ToolStripItem^) sender;
    if ((item->TextDirection == ToolStripTextDirection::Vertical270) 
        || (item->TextDirection == ToolStripTextDirection::Vertical90))
        item->TextDirection = ToolStripTextDirection::Horizontal;
        movingToolStrip->Raft = RaftingSides::Top;
        item->TextDirection = 
        movingToolStrip->Raft = RaftingSides::Left;

internal ToolStripButton changeDirectionButton;

private void InitializeMovingToolStrip()
    movingToolStrip = new ToolStrip();

    changeDirectionButton = new ToolStripButton();

    movingToolStrip.AutoSize = true;
    movingToolStrip.RenderMode = ToolStripRenderMode.System;

    changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270;
    changeDirectionButton.Overflow = ToolStripItemOverflow.Never;
    changeDirectionButton.Text = "Change Alignment";

private void changeDirectionButton_Click(object sender, EventArgs e)

    ToolStripItem item = (ToolStripItem)sender;

    if (item.TextDirection == ToolStripTextDirection.Vertical270 || item.TextDirection == ToolStripTextDirection.Vertical90)
        item.TextDirection = ToolStripTextDirection.Horizontal;
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top;
        item.TextDirection = ToolStripTextDirection.Vertical270;
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left;
Friend WithEvents changeDirectionButton As ToolStripButton

Private Sub InitializeMovingToolStrip()
    changeDirectionButton = New ToolStripButton()

    movingToolStrip.AutoSize = True
    movingToolStrip.RenderMode = ToolStripRenderMode.System

    changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270
    changeDirectionButton.Overflow = ToolStripItemOverflow.Never
    changeDirectionButton.Text = "Change Alignment"
End Sub

Public Sub changeDirectionButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles changeDirectionButton.Click

    Dim item As ToolStripItem = CType(sender, ToolStripItem)

    If item.TextDirection = ToolStripTextDirection.Vertical270 _
        OrElse item.TextDirection = ToolStripTextDirection.Vertical90 Then

        item.TextDirection = ToolStripTextDirection.Horizontal
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top
        item.TextDirection = ToolStripTextDirection.Vertical270
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left
    End If

End Sub


Click 事件会将 EventArgs 传递给其事件处理程序,因此它只指示发生了单击操作。The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. 如果需要更具体的鼠标信息(按钮、单击次数、滚轮旋转或位置),请使用 MouseDown,并 MouseUpMouseEventArgs 传递到事件处理程序的事件。If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseDown and MouseUp events which pass a MouseEventArgs to the event handler.

双击由用户操作系统的鼠标设置确定。A double-click is determined by the mouse settings of the user's operating system. 用户可以设置两次单击鼠标按钮之间的时间以便将这两次单击认为是双击而不是两次单击。The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. 每次双击控件时都会引发 Click 事件。The Click event is raised every time a control is double-clicked. 例如,如果有两个事件处理程序用于 ClickDoubleClick Form的事件,则在双击窗体并调用这两个方法时,将引发 ClickDoubleClick 事件。For example, if you have two event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called. 如果双击的项不支持 DoubleClick 事件,则可能会引发两次 Click 事件。If an item is double-clicked that does not support the DoubleClick event, the Click event might be raised twice.