在组合框VB​​.NET中禁用鼠标滚轮 [英] Disable mouse scroll wheel in combobox VB.NET

查看:908
本文介绍了在组合框VB​​.NET中禁用鼠标滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道一个方法,当一个控件,如组合框或列表框有焦点时,禁用鼠标滚轮?为我的目的,组合框是我需要的答案。

Does anyone know of a way to disable the mouse scroll wheel when a control such as a combobox or listbox has focus? For my purposes, combobox is all I need the answer for.

我有一个组合框设置为触发一个SQL查询SelectedIndexChanged,并意外滚动车轮,而组合框焦点导致大约六个SQL查询同时触发。

I have a combobox set to trigger a SQL query on SelectedIndexChanged, and accidentally scrolling the wheel while the combobox has focus causes about six SQL queries to fire off simultaneously.

推荐答案

ComboBox控件不允许您轻松覆盖MouseWheel事件的行为。向项目中添加一个新类,并粘贴以下代码。编译。将新控件从工具箱顶部拖到表单上。

The ComboBox control doesn't let you easily override behavior of the MouseWheel event. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

Friend Class MyComboBox
    Inherits ComboBox

    Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
        Dim mwe As HandledMouseEventArgs = DirectCast(e, HandledMouseEventArgs)
        mwe.Handled = True
    End Sub
End Class

注意,这也会禁用下拉列表中的滚轮。

Beware that this also disables the wheel in the dropdown list.

这篇关于在组合框VB​​.NET中禁用鼠标滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆