ToolStripItem.Click ToolStripItem.Click ToolStripItem.Click ToolStripItem.Click Event

定義

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 

次のコード例はText、、 Overflow、およびTextDirectionの各プロパティを設定し、 Clickイベントを処理する方法を示しています。The following code example demonstrates how to set the Text, Overflow, and TextDirection properties, and handle the Click event. この例を実行するにはToolStrip 、という名前movingToolStripのを含むフォームに次のコードを貼り付け、フォームLoadのコンストラクターまたはイベントハンドラーにを呼び出しInitializeMovingToolStripます。To 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. ユーザーは、2 回のクリックではなくダブルクリックと見なされるマウス ボタンのクリック間隔を設定できます。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イベントに対して2つのイベントハンドラーがある場合ClickDoubleClickフォームがダブルクリックされ、両方のFormメソッドが呼び出されると、イベントとイベントが発生します。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をサポートしていない項目がダブルクリックされた場合、イベントが2回発生する可能性があります。If an item is double-clicked that does not support the DoubleClick event, the Click event might be raised twice.

適用対象