gpt4 book ai didi

c# - 如何将鼠标滚轮事件中的计时器间隔更改为快和慢?

转载 作者:太空宇宙 更新时间:2023-11-03 19:12:56 27 4
gpt4 key购买 nike

代码:

private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
if (leave == true)
{
timer1.Interval = 10;
}
}

我想这样做,如果我将鼠标滚轮向下转动,它会减慢计时器并增加间隔时间,如果我向上转动鼠标滚轮,它会减少间隔时间。

我该怎么做?

最佳答案

使用MouseEventArgs.Delta属性(property)

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. 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).

private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0) //moved forward
{
timer1.Interval += 1000;
}
else //moved backword
{
timer1.Interval -= 1000;
}
}

关于c# - 如何将鼠标滚轮事件中的计时器间隔更改为快和慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19320940/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com