disabling mousewheel on conbobox

  • Thread starter Thread starter Roger Uribe
  • Start date Start date
R

Roger Uribe

There are references to using the wndproc form sub to trap and swallow the
mousewheeel events - but they don't get there when a combobox (or many other
controls) has the focus.. Yet the MSDN does suggest this is a way to stop
the mousewheel scrolling a combobox

anyone know the REAL answer???

Thanks
Roger
 
* "Roger Uribe said:
There are references to using the wndproc form sub to trap and swallow the
mousewheeel events - but they don't get there when a combobox (or many other
controls) has the focus.. Yet the MSDN does suggest this is a way to stop
the mousewheel scrolling a combobox

I am interested to know /why/ you want to do that.
 
amen

I used to have a webform with an autopostback dropdown. Found out when
people used the mouse wheel to scroll the page, it would cause the postback
on the dropdown if that was where the focus was. Grrrr...

Greg
 
so... somebody, somewhere MUST know how to prevent it - not on web forms,
bit in a vb.net app surely
 
If you are trying to capture the mouse wheel event in the WndProc of the
form, then you're right - when the focus is on the combobox the mousewheel
events dont seem to be passed to the form which is why they don't appear in
the WndProc of the form. However, the event is still fired since that is how
the selection is being changed. In order to eat up the mouse wheel events in
a combobox, you'll have to create a custom control that inherits from the
combobox (I'm not sure of "have to" but thats what I found working :)).
Within the control, you can override the control's WndProc and eat up the
mouse wheel messages. Here's what my control looks like:

Public Class UserControl1
Inherits System.Windows.Forms.ComboBox

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case &H20A
Debug.WriteLine("mouse wheel on combo")
Case Else
MyBase.WndProc(m)
End Select
End Sub
End Class

Just build a control class library containing this control. For testing
purposes, have your project and this control class library in the same
project and then add the control to your form from the designer (you should
see the new control under 'My User Controls' instead of 'Windows Forms' in
the toolbox). Just add a couple of items to the combo and run your project.
Try your mouse scroll on the user control and voila! you should have them
'eaten' up..

hope this helps..
Imran.
 
Excellent!!!!!!!!!!!!!!!!
I had a few unexpected problems renaming it from UserControl1 to myComboBox
but that apart the principle works brilliantly

Thank-you
Roger
 
Back
Top