开发者

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

开发者 https://www.devze.com 2023-01-08 14:09 出处:网络
I want to hook a mouse wheel event to my scroll bar but i cannot see mouse开发者_StackOverflow中文版 wheel event in control properties. I have a form on which i have a panel and a vertical scroll bar.

I want to hook a mouse wheel event to my scroll bar but i cannot see mouse开发者_StackOverflow中文版 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??


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

精彩评论

暂无评论...
验证码 换一张
取 消