views:

421

answers:

1

I have a UserControl containing TextBoxes and ComboBoxes and this UserControl is contained in a Panel with AutoScroll set to True.

When a textbox has the focus and I scroll with the mouse wheel, then the panel scrolls, when a combobox has the focus and I scroll with the mouse wheel then the selected item in the combobox changes.

I'm sure this is the intended behaviour but it is something I'd like to change, so that all mousewheel events scroll the panel.

To do this I am handling the WM_MOUSEWHEEL message in the WndProc method in a ComboBox subclass as follows:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    Const WM_MOUSEWHEEL As Integer = &H20A
    Select Case m.Msg
        Case WM_MOUSEWHEEL
            ' Send the message to the parent
            GetType(Control).InvokeMember("WmMouseWheel", Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic, Nothing, Parent, New Object() {m})
            Return
    End Select
    MyBase.WndProc(m)
End Sub

Is there a way to do this without resorting to calling a private method on a control via reflection?

+2  A: 

You could use the Win32 SendMessage function to forward the contents of your message, m, to Parent.Handle.

Tim Robinson