I have created a panel that has several objects on it. Autoscroll is set to true, so when the number of objects exceeds the visible bounds, the panel automatically adds scrollbars. I want to be able to use the mouse wheel to scroll the panel; however, I would like not to be forced to give the panel focus in order to do so.
I have been experimenting with IMessageFilter to pre-process the mouse wheel event (actually the WM_MOUSEWHEEL message). The code I have been working with is below, and yes, I have added the message filter to the form, even though that line of code is not below. Some code snippets online suggested using SendMessage() to relay the message to the Panel without it needing focus. Would I be correct in my assumption that the panel will process the WM_MOUSEWHEEL message even though it does not have focus?
To summarize, my overall intent is to have the panel be scrollable with the mouse wheel, and only when the mouse is over the panel, not always. My preference is to not give the panel focus and still be able to scroll with the mouse wheel.
Thanks in advance!
const int WM_MOUSEWHEEL = 0x020A;
public bool PreFilterMessage(ref Message m)
if (m.HWnd == this.taskPanel1.Handle && m.Msg == WM_MOUSEWHEEL)
SendMessage(this.taskPanel1.Handle, m.Msg, m.WParam, m.LParam);
m.Result = IntPtr.Zero;