MouseEventArgs.Delta 屬性

定義

取得滑鼠滾輪滾動時帶有正負號的刻度數乘以 WHEEL_DELTA 常數。Gets a signed count of the number of detents the mouse wheel has rotated, multiplied by the WHEEL_DELTA constant. 一個刻度是一個滑鼠滾輪的刻痕。A detent is one notch of the mouse wheel.

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

屬性值

滑鼠滾輪滾動時帶有正負號的刻度數乘以 WHEEL_DELTA 常數。A signed count of the number of detents the mouse wheel has rotated, multiplied by the WHEEL_DELTA constant.

範例

下列程式碼範例示範如何使用這個成員。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

備註

滑鼠滾輪結合了滾輪和滑鼠按鍵的功能。The mouse wheel combines the features of a wheel and a mouse button. 滾輪具有離散、平均間距的凹槽。The wheel has discrete, evenly spaced notches. 當您旋轉滾輪時, 會隨著每個槽口的出現而傳送滾輪訊息。When you rotate the wheel, a wheel message is sent as each notch is encountered. 一個輪子槽口 (一個 detent) 是由 windows 常數 WHEEL_DELTA 所定義, 也就是120。One wheel notch, a detent, is defined by the windows constant WHEEL_DELTA, which is 120. 正值表示滾輪已向前旋轉 (遠離使用者);負值表示滾輪已向後旋轉 (朝向使用者)。A positive value indicates that the wheel was rotated forward (away from the user); a negative value indicates that the wheel was rotated backward (toward the user).

目前, 120 的值是一個 detent 的標準。Currently, a value of 120 is the standard for one detent. 如果引進較高解析度的滑鼠, WHEEL_DELTA 的定義可能會變小。If higher resolution mice are introduced, the definition of WHEEL_DELTA might become smaller. 大部分的應用程式都應該檢查正值或負值, 而不是匯總總計。Most applications should check for a positive or negative value rather than an aggregate total.

適用於

另請參閱