ToolStripItem.Click 事件

定義

發生於按一下 ToolStripItem 時。Occurs when the ToolStripItem is clicked.

public:
 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 = 
        ToolStripTextDirection::Vertical270;
    changeDirectionButton->Overflow = 
        ToolStripItemOverflow::Never;
    changeDirectionButton->Text = "Change Alignment";
    movingToolStrip->Items->Add(changeDirectionButton);
    changeDirectionButton->Click += gcnew EventHandler(this, 
        &Form1::changeDirectionButtonClick);
}

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;
    }
    else
    {
        item->TextDirection = 
            ToolStripTextDirection::Vertical270;
        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";
        movingToolStrip.Items.Add(changeDirectionButton);
}

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;
    }
    else
    {
        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"
    movingToolStrip.Items.Add(changeDirectionButton)
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
    Else
        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,並 MouseUp 會將 MouseEventArgs 傳遞至事件處理常式的事件。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. 例如,如果您有兩個事件處理常式適用于 FormClickDoubleClick 事件,則當按兩下表單並呼叫這兩種方法時,就會引發 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.

適用於