tags:

views:

41

answers:

1

I want to hook a mouse wheel event to my scroll bar but i cannot see mouse wheel event in control properties. I have a form on which i have a panel and a vertical scroll bar. So far my scroll bar doesn't work with the mouse wheel. I need that event to hook it with my scroll bar. How to do it??

+4  A: 

You need to attach to the MouseWheel event:

Occurs when the mouse wheel moves while the control has focus.

For example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.MouseWheel += new MouseEventHandler(MouseWheelEvent);
        this.MouseMove += new MouseEventHandler(MouseWheelEvent);
    }

    private void MouseWheelEvent(object sender, MouseEventArgs e)
    {
        Console.Out.WriteLine(e.Delta);
    }
}
SwDevMan81
but how to make it work that is make it scroll when i roll the mouse wheel? It is not working!
ghd
I have a custom scroll bar and not auto scroll bar.
ghd
Check out http://stackoverflow.com/questions/262534/how-to-scroll-a-panel-manually. Then you could put something like c.VerticalScroll.Value += e.Delta; in the MouseWheelEvent above. Is that more what you are looking for?
SwDevMan81