4
votes

I bring the focus on a scrollbar with vScrollBar.Select(); The scroll bar becomes focused but it doesn't scroll with mouse wheel.

It scrolls only if the mouse cursor is over the scrollbar.

How to make the scrollbar scrolling after Select() without placing the cursor over the scrollbar?

Environment: Windows 10, Windows forms, .NET 4.0

EDIT

I noticed that the scrollbar scrolls properly when I "scroll" with two fingers on the laptop touch pad, but not with the mouse wheel. Is it possible the problem to be because of a Windows 10 mouse/touch pad driver?

3
Use Spy++, tell us which window gets the WM_MOUSEWHEEL message.Hans Passant
@HansPassant When mouse is over the panel, the panel receives the WM_MOUSEWHEEL message. When I move over the scrollbar, it receives the WM_MOUSEWHEEL messages. When I scroll over the panel with the touch pad, the scrollbar scrolls. s13.postimg.org/n8jpc1blz/screenshot_1097.pngMiroslav Popov

3 Answers

8
votes

I just got Win10 up and running, confirmed. This is a side-effect of a new Windows 10 feature, configured in Settings > Devices > Mouse & touchpad. It is named "Scroll inactive windows when I hover over them", it is turned on by default. This web page mentions it.

This is actually a very nice feature, I'll personally definitely keep it on and it is pretty likely your users will as well. Previous Windows versions sent the mouse wheel messages to the control with the focus, mystifying a great many users that got used to the way the mouse behaves in, say, a browser. Do note that the scrollbar helps, it redraws the thumb to indicate that it is no longer active when you move the mouse off the bar.

Fixing it is technically possible, you'll have to redirect the message back to the scrollbar. Nothing particularly pretty:

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

But don't jump the gun yet, your users are apt to expect the Win10 behavior, eventually :)

0
votes

To use a Winforms scrollbar using the mousewheel, don't Select() the Scrollbar itself, you have to select the panel, image, or whatever it is you made scrollable.

-1
votes

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!