c# - 如何检测鼠标滚轮方向(向前或向后)

标签 c# winforms scroll

我需要知道如何在 MouseWheel 事件上确定滚动是向前还是向后(不是垂直或水平)。

panel1.MouseWheel += ZoomIn

public void ZoomIn(object sender, EventArgs e)
{
     // Need to know whether the wheel is scrolled forwards or backwards
}

最佳答案

而不是 EventArgs使用 MouseEventArgs 其中暴露了 Delta 属性(property)。
向下滚动时为负,向上滚动时为正。

panel1.MouseWheel += ZoomIn;

public void ZoomIn(object sender, MouseEventArgs e)
{
    if(e.Delta > 0)
    {
        // The user scrolled up.
    }
    else
    {
        // The user scrolled down.
    }
}

关于c# - 如何检测鼠标滚轮方向(向前或向后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49529144/

相关文章:

c# - ClosedXML - 创建多个数据透视表

c# - ShowDialog 中的 Catel async wait 命令 - 死锁

c# - 使用insert方法绕过sql注入(inject)

javascript - C# Regex 性能纯相对 JS

c# - TableLayoutPanel 对事件的响应非常慢

c# - MessageBox 中的粗体文本

javascript - 动画滚动到滚动上的特定页面位置

c# - BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍未改变

javascript - 同一页面中的多个 p5.js Canvas

iphone - Cocos2d滚动游戏TileMap碰撞