Changing MouseWheel Combobox Behavior

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

When the textbox has focus and I scroll with the mouse wheel then the pane is scrolled, when the combo box has focus and I scroll with the mouse wheel then the selected item in the combo box changes.

I'm sure this is intentional behavior, but this is what I would like to change so that all events in the mousewheel scroll the panel.

To do this, I process the WM_MOUSEWHEEL message in the WndProc method in the 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 control method through reflection?

0


a source to share


1 answer


You can use a Win32 function SendMessage

to forward the content of your message m

to Parent.Handle

.



+2


a source







All Articles