Saturday, February 16, 2008

Capturing Mouse Wheel event in C#

Not sure why, but MS chose not to display the MouseWheel event in the Event box. However, it is quite easy to hook it through the editor.

Assuming you're using Visual Studio 2005 or 2008, it's an one step process, really -

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

It's that easy! Told you, it's one step process.

4 comments:

  1. sorry I'm not comment about what you post - I need your help - May I have your uvmodeller's source code ? please send to my email gryfindor_hu22188@yahoo.co.id

    I've sent 3 email to your hirak_99@myrealbox.com but failed. so I hope you see this comment and can help me. I'm so apreciated it.

    ReplyDelete
  2. You can download UVModeller source code from Google Code project here:
    http://code.google.com/p/uvmodeller/source/checkout

    ReplyDelete
  3. it's really coooooool.
    but how can i count how many times it is wheeled to forward and backward?

    ReplyDelete
  4. Thanx!!! This did it:

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

    Example:

    MouseWheel += new MouseEventHandler(Form2_MouseWheel);

    void Form2_MouseWheel(object sender, MouseEventArgs e)
    {
    //throw new NotImplementedException();
    if (e.Delta > 0)
    {
    index--;
    else
    {
    index++;
    }
    }

    ReplyDelete