MouseWheelEventArgs.Delta 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取指示鼠标滚轮变更量的值。
public:
property int Delta { int get(); };
public int Delta { get; }
member this.Delta : int
Public ReadOnly Property Delta As Integer
属性值
鼠标滚轮的变更量。 如果鼠标滚轮朝上旋转(背离用户的方向),则该值为正;如果鼠标滚轮朝下旋转(朝着用户的方向),则该值为负。
示例
以下示例TextBox在鼠标滚轮为正数时向上移动 ;如果鼠标滚轮DeltaDelta为负数,则向下移动 TextBox 。 附加到 TextBoxCanvas。
// 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
注解
此值的有效上限和下限范围可能来自引发事件的设备实现或其他调用方,因此未定义。