【问题标题】:How to hook a mouse wheel event to a form that has a panel and a scroll bar如何将鼠标滚轮事件挂钩到具有面板和滚动条的表单
【发布时间】:2010-07-20 11:04:05
【问题描述】:

我想将鼠标滚轮事件挂接到滚动条,但在控件属性中看不到鼠标滚轮事件。我有一个表单,上面有一个面板和一个垂直滚动条。到目前为止,我的滚动条不适用于鼠标滚轮。我需要该事件将它与我的滚动条挂钩。怎么办??

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您需要附加到MouseWheel 事件:

    当鼠标滚轮移动而控件具有焦点时发生。

    例如:

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

    【讨论】:

    • 但是当我滚动鼠标滚轮时如何让它工作呢?它不工作!
    • 我有一个自定义滚动条,而不是自动滚动条。
    • 查看stackoverflow.com/questions/262534/…。然后你可以放一些像 c.VerticalScroll.Value += e.Delta;在上面的 MouseWheelEvent 中。这就是你要找的东西吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 2012-10-19
    • 1970-01-01
    • 2013-06-25
    相关资源
    最近更新 更多