How to hook a mouse wheel event to a form that has a panel and a scroll bar

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??

Answers


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);
    }
}

Need Your Help

Centroid of matrix

java algorithm centroid

Given a 2D array, I am required to come up with an algorithm which outputs the center of mass. I came up with algorithm below, however, it is producing incorrect solution when the array size is inc...