Mouse scroll without focusing on ImageBox

Started by wmjordan, February 12, 2015, 04:48:45 AM

Previous topic - Next topic

wmjordan

Hello,

To use the mouse wheel to scroll the image in the ImageBox control, currently we have to click onto the control and make it focused first, and then we handle the OnMouseWheel event. If the control is not focused the MouseWheel event won't get fired.

If we handle the OnMouseEnter event and make the control get focused, the user can afterwards use the wheel to scroll the image, however this will steal the focus from other controls, for example, another text editor control in a form. That is not so good user experience.

Is it possible to receive the mouse wheel event without the control getting focused?

Richard Moss

#1
I ran Spy++ and checked which messages were being sent to the window, however it doesn't look like the WM_MOUSEWHEEL message (which the events depend on) is transmitted to windows without focus.

It might be possible using a mouse hook, but not really something I'm looking into doing - I vaguely remember trying to do something with global hooks (or similar, foggy memory!) in VB6 many years ago and the results were unstable. Unfortunately I can't think of any other ideas off the top of my head.

It will also "break" standard functionality. Consider the demo application - if the grid in one of the demo forms has focus and you move your mouse over the image box then spin the wheel, you will see the grid scrolls. Having potentially two different controls suddenly reacting to mouse spins probably wouldn't be a good user experience either!

Not a terribly helpful reply...

Regards;
Richard Moss
Read "Before You Post" before posting (https://forums.cyotek.com/cyotek-webcopy/before-you-post/). Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

wmjordan

Hello, thanks for the investigation and explanation.

While I was reading PDF files with an open source PDF reader--SumatraPDF, which allowed me to scroll the document window (the viewer control on the right panel) while the focus still remained in the Bookmark panel (the control on the left panel). I think it was quite convenient. I was just curios about that whether the same behavior can be implemented in ImageBox.

mtagliaf

I'm new to the forum, but I found a solution to this same problem earlier this week.  Two different implementations are here.

http://stackoverflow.com/questions/11034348/mouse-wheel-event-to-work-with-hovered-control

Richard Moss

Hello and welcome to the forums!

Thanks for the link, I just tested using a message filter and it worked, and that is definitely a viable solution without worry about the pain of hooks.

I'll adapt this for the next update to the control - not sure if it's something I'll add to the core control, but I'll definitely make it a part of the demo at the very least.

Regards;
Richard Moss
Read "Before You Post" before posting (https://forums.cyotek.com/cyotek-webcopy/before-you-post/). Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

Richard Moss

I've just posted a new version of the ImageBox control that offers a new AllowUnfocusedMouseWheel property. When set to true (not the default), it will allow the ImageBox to zoom with the mouse wheel even when the control doesn't have focus.

Oh, and I updated the NuGet package for the first time in an eternity too.
Read "Before You Post" before posting (https://forums.cyotek.com/cyotek-webcopy/before-you-post/). Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

wmjordan

Thank you all guys for the help.
It works.