MouseEventArgs.Clicks プロパティ

定義

マウス ボタンが押されて離された回数を取得します。

public:
 property int Clicks { int get(); };
public int Clicks { get; }
member this.Clicks : int
Public ReadOnly Property Clicks As Integer

プロパティ値

マウス ボタンが押されて離された回数を含む Int32

次のコード例は、このメンバーの使用方法を示しています。 この例では、イベント ハンドラーは、 Control.MouseClick イベントの発生を報告します。 このレポートは、イベントがいつ発生するかを学習するのに役立ち、デバッグに役立ちます。 複数のイベントや頻繁に発生するイベントについて報告するには、 MessageBox.ShowConsole.WriteLine に置き換えるか、メッセージを複数行の TextBoxに追加することを検討してください。

コード例を実行するには、ControlButtonなど、ComboBoxから継承する型のインスタンスを含むプロジェクトに貼り付けます。 次に、インスタンスに Control1 という名前を付け、イベント ハンドラーが Control.MouseClick イベントに関連付けられていることを確認します。

private void Control1_MouseClick(Object sender, MouseEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Button", e.Button );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Clicks", e.Clicks );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Delta", e.Delta );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Location", e.Location );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "MouseClick Event" );
}
Private Sub Control1_MouseClick(sender as Object, e as MouseEventArgs) _ 
     Handles Control1.MouseClick

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Button", e.Button)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Clicks", e.Clicks)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Delta", e.Delta)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Location", e.Location)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"MouseClick Event")

End Sub

注釈

Windows インターフェイスでは、標準のマウス イベントがシングル クリックまたはダブルクリックとして定義されていますが、個々のアプリケーションでは、より多くのクリックを 1 つのイベントとして解釈できます。

適用対象

こちらもご覧ください