MouseWheelEventArgs.Delta 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示鼠标滚轮已更改的量。
public:
property int Delta { int get(); };
public int Delta { get; }
member this.Delta : int
Public ReadOnly Property Delta As Integer
属性值
滚轮已更改的量。 如果鼠标滚轮向向上方向(远离用户)旋转,或者鼠标滚轮在向下方向(向用户旋转),则此值为正值。
示例
以下示例在鼠标滚轮为正时向上移动TextBox,并在鼠标滚Delta轮TextBox为负时向下移动Delta。 附加到 TextBox .Canvas
// Moves the TextBox named box when the mouse wheel is rotated.
// The TextBox is on a Canvas named MainCanvas.
private void MouseWheelHandler(object sender, MouseWheelEventArgs e)
{
// If the mouse wheel delta is positive, move the box up.
if (e.Delta > 0)
{
if (Canvas.GetTop(box) >= 1)
{
Canvas.SetTop(box, Canvas.GetTop(box) - 1);
}
}
// If the mouse wheel delta is negative, move the box down.
if (e.Delta < 0)
{
if ((Canvas.GetTop(box) + box.Height) <= (MainCanvas.Height))
{
Canvas.SetTop(box, Canvas.GetTop(box) + 1);
}
}
}
' Moves the TextBox named box when the mouse wheel is rotated.
' The TextBox is on a Canvas named MainCanvas.
Private Sub MouseWheelHandler(ByVal sender As Object, ByVal e As MouseWheelEventArgs)
' If the mouse wheel delta is positive, move the box up.
If e.Delta > 0 Then
If Canvas.GetTop(box) >= 1 Then
Canvas.SetTop(box, Canvas.GetTop(box) - 1)
End If
End If
' If the mouse wheel delta is negative, move the box down.
If e.Delta < 0 Then
If (Canvas.GetTop(box) + box.Height) <= MainCanvas.Height Then
Canvas.SetTop(box, Canvas.GetTop(box) + 1)
End If
End If
End Sub
注解
此值的有效上限和较低范围可能来自引发事件的设备实现或其他调用方,因此未定义。