ScrollBar不会在Select()上滚动

时间:2015-07-29 11:13:05

标签: winforms .net-4.0 scrollbar windows-10

我将重点放在vScrollBar.Select();的滚动条上 滚动条变得聚焦但不会滚动鼠标滚轮。

仅当鼠标光标位于滚动条上时才会滚动。

如何在不将光标放在滚动条上而使Select()后滚动条滚动?

  

环境:Windows 10,Windows窗体,.NET 4.0

修改

当我用笔记本电脑触摸板上的两个手指“滚动”时,我注意到滚动条正确滚动,但不是鼠标滚轮。 问题可能是因为Windows 10鼠标/触摸板驱动程序?

3 个答案:

答案 0 :(得分:8)

我刚刚启动并运行Win10,确认。这是新的Windows 10功能的副作用,在“设置”>中配置。装置>鼠标&触摸板。当我将鼠标悬停在"上时,它被命名为#34;滚动非活动窗口,默认情况下它处于打开状态。 This web page提及它。

这实际上是非常很好的功能,我个人肯定会继续使用它,很可能你的用户也会这样做。以前的Windows版本将鼠标滚轮消息发送到具有焦点的控件,使许多习惯了鼠标行为的用户神秘化,例如浏览器。请注意滚动条有帮助,当您将鼠标移开栏时,它会重绘拇指以指示它不再处于活动状态。

修复它在技术上是可行的,您必须将消息重定向回滚动条。没什么特别漂亮的:

    public Form1() {
        InitializeComponent();
        panel1.MouseWheel += RedirectMouseWheel;
    }

    private bool redirectingWheel;

    private void RedirectMouseWheel(object sender, MouseEventArgs e) {
        if (this.ActiveControl != sender && !redirectingWheel) {
            redirectingWheel = true;
            SendMessage(this.ActiveControl.Handle, 0x020A, 
                new IntPtr(e.Delta << 16), IntPtr.Zero);
            redirectingWheel = false;
            var hmea = (HandledMouseEventArgs)e;
            hmea.Handled = true;
        }
    }
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

但是还没有跳过枪,你的用户很容易期待Win10的行为,最终:)

答案 1 :(得分:0)

要使用鼠标滚轮使用Winforms滚动条,请不要Select()滚动条本身,您必须选择面板,图像或您可滚动的任何内容。

答案 2 :(得分:-1)

Not sure about you guys having problems with your mouse in the new Windows 10. I had a lot pf issues and a lot of research, and changing the settings. Tried all that was recommended. All of this in Explorer. I changed over to Mozilla Firefox, and are having no issues at all. Everything works perfectly. May be an option for you to consider. If you are using Firefox, and are having an issue, don't know there. Good luck!