Cancel mouse wheel scrolling in a combobox VB.NET
-
I am trying to cancel the mouse wheel scrolling in a combobox and I noticed that there is a Combobox.MouseWheel event but that just relays information it doesnt allow me to cancel the event. This is the only thing I have found with some type of definite answer[^] and it looks like something that I dont want to do unless I have to.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
-
I am trying to cancel the mouse wheel scrolling in a combobox and I noticed that there is a Combobox.MouseWheel event but that just relays information it doesnt allow me to cancel the event. This is the only thing I have found with some type of definite answer[^] and it looks like something that I dont want to do unless I have to.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
That's the only way you're going to be able to do it. You have to intercept the Scroll Wheel messages before they get processed by the controls WndProc.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
That's the only way you're going to be able to do it. You have to intercept the Scroll Wheel messages before they get processed by the controls WndProc.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Here's what Im trying and it doesnt pick up the scrolling while focused on the combobox only if I scroll with the mousewheel while focused anywhere else does it work.
Private Const WM_MOUSEWHEEL As Integer = &H20A Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM_MOUSEWHEEL Select Case True Exit Sub End Select MyBase.WndProc(m) End Sub
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
-
Here's what Im trying and it doesnt pick up the scrolling while focused on the combobox only if I scroll with the mousewheel while focused anywhere else does it work.
Private Const WM_MOUSEWHEEL As Integer = &H20A Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM_MOUSEWHEEL Select Case True Exit Sub End Select MyBase.WndProc(m) End Sub
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
Where is this code?? Is it on your Form or is it part of a custom ComboBox control?? This code has to be part of a custom ComboBox to work. You got it mostly right. Though, your
Select Case
is really messed up. You don't need theSelect Case True
. That will ALWAYS execute it's code no matter what. All you want is to NOT process MouseWheel messages. All other MUST be passed to the base ComboBox control. Soooo....Public Class MyComboBox
Inherits ComboBoxPrivate Const WM\_MOUSEWHEEL As Integer = &H20A Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM\_MOUSEWHEEL ' If we see a MouseWheel message, do not process it! Exit Sub End Select ' All other messages get processed as normal. MyBase.WndProc(m) End Sub
End Class
... is what you're looking for.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Where is this code?? Is it on your Form or is it part of a custom ComboBox control?? This code has to be part of a custom ComboBox to work. You got it mostly right. Though, your
Select Case
is really messed up. You don't need theSelect Case True
. That will ALWAYS execute it's code no matter what. All you want is to NOT process MouseWheel messages. All other MUST be passed to the base ComboBox control. Soooo....Public Class MyComboBox
Inherits ComboBoxPrivate Const WM\_MOUSEWHEEL As Integer = &H20A Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM\_MOUSEWHEEL ' If we see a MouseWheel message, do not process it! Exit Sub End Select ' All other messages get processed as normal. MyBase.WndProc(m) End Sub
End Class
... is what you're looking for.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007I sure was hoping it was easier but no biggie. Ive dont a few custom controls in my day...:). That select true used to contain code by the way but I was still in the middle of messing with it.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)