I need to know how to determine the scroll whether is forward or backward(not vertical or horizontal) on MouseWheel event.
panel1.MouseWheel += ZoomIn
public void ZoomIn(object sender, EventArgs e)
{
// Need to know whether the wheel is scrolled forwards or backwards
}
Instead of EventArgs
use MouseEventArgs
which expose the Delta
property.
It is negative on down scrolling and positive on upscrolling.
panel1.MouseWheel += ZoomIn;
public void ZoomIn(object sender, MouseEventArgs e)
{
if(e.Delta > 0)
{
// The user scrolled up.
}
else
{
// The user scrolled down.
}
}
Per MSDN:
When handling the MouseWheel event it is important to follow the user interface (UI) standards associated with the mouse wheel. The MouseEventArgs.Delta property value indicates the amount the mouse wheel has been moved. The UI should scroll when the accumulated delta is plus or minus 120. The UI should scroll the number of logical lines returned by the SystemInformation.MouseWheelScrollLines property for every delta value reached. You can also scroll more smoothly in smaller that 120 unit increments, however the ratio should remain constant, that is SystemInformation.MouseWheelScrollLines lines scrolled per 120 delta units of wheel movement.
So you want to change the type of e
in your handler to be MouseEventArgs
(or introduce a cast), and then use its Delta
property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With