MouseEventArgs.Clicks 屬性

定義

取得按下並釋放滑鼠鍵的次數。Gets the number of times the mouse button was pressed and released.

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

屬性值

Int32,包含按下並釋放滑鼠按鍵的次數。An Int32 that contains the number of times the mouse button was pressed and released.

範例

下列程式碼範例示範如何使用這個成員。The following code example demonstrates the use of this member. 在此範例中, 事件處理常式會報告Control.MouseClick事件的發生次數。In the example, an event handler reports on the occurrence of the Control.MouseClick event. 此報表可協助您瞭解事件發生的時間, 並可協助您進行調試。This report helps you learn when the event occurs and can assist you in debugging. 若要報告多個事件或經常發生的事件, 請考慮MessageBox.ShowConsole.WriteLine取代為, 或將訊息附加TextBox至多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要執行範例程式碼, 請將它貼到包含繼承自Control之類型實例的專案中, 例如ButtonComboBoxTo run the example code, paste it into a project that contains an instance of a type that inherits from Control, such as a Button or ComboBox. 然後為實例Control1命名, 並確定事件處理常式Control.MouseClick與事件相關聯。Then name the instance Control1 and ensure that the event handler is associated with the Control.MouseClick event.

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 介面會將標準滑鼠事件定義為單鍵或按兩下, 但個別應用程式可以將更多的點擊次數解讀為單一事件。Although the Windows interface defines standard mouse events as either single-clicks or double-clicks, individual applications can interpret a larger number of clicks as a single event.

適用於

另請參閱