-
Jul 19th, 2022, 12:34 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Disable Scroll on ComboBox MouseOver
Hi there,
I have a ComboBox inside a TableLayoutPanel, inside another TableLayoutPanel, inside a Panel. The Panel has scrolling enabled when the Form windows is resized smaller than the content.
When scrolling down the Panel with the MouseWheel, if the cursor enters one of several ComboBoxes the Panel scrolling stops and instead the ComboBox's items are scrolled through.
I've found a code example for creating a Custom Control as follows:
vb Code:
Public Class CustomComboBox
Inherits ComboBox
Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
Dim mwe As HandledMouseEventArgs = DirectCast(e, HandledMouseEventArgs)
mwe.Handled = True
End Sub
End Class
Upon cursor entering this did stop the ComboBox items from being scrolled through, however it also stopped the scrolling of the Panel.
There was an additional post that mentioned this stating to add
vb Code:
Parent.Focus
'or
Parent.Parent.Parent.Focus 'etc.
'after
mwe.Handled = True
This didn't make any difference for me, on Windows 11 I can still see that with the cursor over the ComboBox it MouseOver/Focus colour change is still active.
Does anyone know to keep the Panel the focus of the scroll when the cursor enters a ComboBox please?
Thank you in advance.
-
Jul 19th, 2022, 06:53 PM
#2
Re: Disable Scroll on ComboBox MouseOver
You need to use some method of the ComboBox to set the focus back to the form or TableLayoutPanel or panel that is the parent of the ComboBox
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 19th, 2022, 06:56 PM
#3
Re: Disable Scroll on ComboBox MouseOver
Possibly use the ComboBox MouseMove event in conjunction with your code for disabling MouseWheel handling, although you may be able to create a Message in the OnMouseWheel event that you’re using and pass to the Form WndProc or DefWndProc. I think there’s a WM_MOUSEWHEEL message, but you’ll need to research that…
Last edited by .paul.; Jul 19th, 2022 at 07:03 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 20th, 2022, 03:54 AM
#4
Thread Starter
Hyperactive Member
Re: Disable Scroll on ComboBox MouseOver
Thanks for the response .paul.
I tried a couple of solutions that used the WM_MOUSEWHEEL aka &H020A, but I couldn't get them to work.
Luckily your mention of this message allowed me to find a neat solution that so far has worked perfectly:
vb Code:
Public Class CustomComboBox
Inherits ComboBox
Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
Dim onMouseWheel As System.Reflection.MethodInfo = Form1.Panel1.[GetType]().GetMethod("OnMouseWheel", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
onMouseWheel.Invoke(Form1.Panel1, New Object() {e})
End Sub
End Class
Thanks again.
-
Jul 20th, 2022, 08:35 AM
#5
Re: Disable Scroll on ComboBox MouseOver
Originally Posted by squatman
Thanks for the response .paul.
I tried a couple of solutions that used the WM_MOUSEWHEEL aka &H020A, but I couldn't get them to work.
Luckily your mention of this message allowed me to find a neat solution that so far has worked perfectly:
vb Code:
Public Class CustomComboBox
Inherits ComboBox
Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
Dim onMouseWheel As System.Reflection.MethodInfo = Form1.Panel1.[GetType]().GetMethod("OnMouseWheel", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
onMouseWheel.Invoke(Form1.Panel1, New Object() {e})
End Sub
End Class
Thanks again.
Good solution. Does the ComboBox still work properly?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 20th, 2022, 11:13 AM
#6
Lively Member
Re: [RESOLVED] Disable Scroll on ComboBox MouseOver
-
Jul 20th, 2022, 12:56 PM
#7
Re: [RESOLVED] Disable Scroll on ComboBox MouseOver
Originally Posted by mmx88_ValidUser
This parse as malware.
??????
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|