我有一个包含 TextBoxes 和 ComboBoxes 的 UserControl,并且此 UserControl 包含在 AutoScroll 设置为 True 的面板中。
当文本框具有焦点并且我使用鼠标滚轮滚动时,面板会滚动,当组合框具有焦点并且我使用鼠标滚轮滚动时,组合框中的选定项目会更改。
我确定这是预期的行为,但我想更改它,以便所有鼠标滚轮事件滚动面板。
为此,我在 ComboBox 子类的 WndProc 方法中处理 WM_MOUSEWHEEL 消息,如下所示:
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
有没有办法做到这一点,而无需通过反射调用控件上的私有方法?