Saturday, 17 November 2012

Capturing Mouse Wheel event in C#

Microsoft chose not to display the MouseWheel event in the Event box. However, it is easy to hook it through the editor.

In the constructor of the Form / custom control, type - "MouseWheel+=", and press TAB twice. Once for completing the statement, and again to insert the handler in the class.

to catch the wheel rotation, if the value of e.Delta >0 then it scrolls up and if the value of e.Delta <0 then it scrolls down:

if (e.Delta < 0)
    x--;
else
    x++;

No comments:

SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...