By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

disabling mousewheel on conbobox

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
* "Roger Uribe" <ne**@roger-u.fsnet.co.uk> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #2

P: n/a
why!! because it is far far too easy to accidentally change the selection.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
* "Roger Uribe" <ne**@roger-u.fsnet.co.uk> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #3

P: n/a
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

"Roger Uribe" <ne**@roger-u.fsnet.co.uk> wrote in message
news:cd**********@news5.svr.pol.co.uk...
why!! because it is far far too easy to accidentally change the selection.

Nov 20 '05 #4

P: n/a
so... somebody, somewhere MUST know how to prevent it - not on web forms,
bit in a vb.net app surely

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eV*************@tk2msftngp13.phx.gbl...
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

"Roger Uribe" <ne**@roger-u.fsnet.co.uk> wrote in message
news:cd**********@news5.svr.pol.co.uk...
why!! because it is far far too easy to accidentally change the

selection.


Nov 20 '05 #5

P: n/a
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.

"Roger Uribe" <ne**@roger-u.fsnet.co.uk> wrote in message
news:cd*********@newsg1.svr.pol.co.uk...
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

Nov 20 '05 #6

P: n/a
Excellent!!!!!!!!!!!!!!!!
I had a few unexpected problems renaming it from UserControl1 to myComboBox
but that apart the principle works brilliantly

Thank-you
Roger
"Imran Koradia" <no****@microsoft.com> wrote in message
news:uN**************@TK2MSFTNGP10.phx.gbl...
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.

"Roger Uribe" <ne**@roger-u.fsnet.co.uk> wrote in message
news:cd*********@newsg1.svr.pol.co.uk...
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


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.