【问题标题】:Modifying the MouseWheel behaviour of a Combobox修改 Combobox 的 MouseWheel 行为
【发布时间】:2009-05-07 15:46:10
【问题描述】:

我有一个包含 TextBoxes 和 ComboBoxes 的 UserControl,这个 UserControl 包含在一个将 AutoScroll 设置为 True 的 Panel 中。

当一个文本框有焦点并且我用鼠标滚轮滚动时,面板会滚动,当一个组合框有焦点并且我用鼠标滚轮滚动时,组合框中的选定项目会发生变化。

我确定这是预期的行为,但我想更改它,以便所有鼠标滚轮事件滚动面板。

为此,我在 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

有没有办法在不通过反射调用控件上的私有方法的情况下做到这一点?

【问题讨论】:

    标签: .net winforms mousewheel


    【解决方案1】:

    您可以使用 Win32 的SendMessage 函数将您的邮件内容m 转发到Parent.Handle

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2013-07-25
      • 2014-05-08
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多