Results 1 to 7 of 7

Thread: [RESOLVED] Disable Scroll on ComboBox MouseOver

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    304

    Resolved [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:
    1. Public Class CustomComboBox
    2.     Inherits ComboBox
    3.  
    4.     Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
    5.         Dim mwe As HandledMouseEventArgs = DirectCast(e, HandledMouseEventArgs)
    6.         mwe.Handled = True
    7.     End Sub
    8. 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:
    1. Parent.Focus
    2.  
    3. 'or
    4.  
    5. Parent.Parent.Parent.Focus 'etc.
    6.  
    7. 'after
    8.  
    9. 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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    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

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    304

    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:
    1. Public Class CustomComboBox
    2.     Inherits ComboBox
    3.  
    4.     Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
    5.         Dim onMouseWheel As System.Reflection.MethodInfo = Form1.Panel1.[GetType]().GetMethod("OnMouseWheel", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
    6.         onMouseWheel.Invoke(Form1.Panel1, New Object() {e})
    7.     End Sub
    8. End Class

    Thanks again.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    Re: Disable Scroll on ComboBox MouseOver

    Quote Originally Posted by squatman View Post
    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:
    1. Public Class CustomComboBox
    2.     Inherits ComboBox
    3.  
    4.     Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
    5.         Dim onMouseWheel As System.Reflection.MethodInfo = Form1.Panel1.[GetType]().GetMethod("OnMouseWheel", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
    6.         onMouseWheel.Invoke(Form1.Panel1, New Object() {e})
    7.     End Sub
    8. End Class


    Thanks again.
    Good solution. Does the ComboBox still work properly?

  6. #6
    Lively Member
    Join Date
    Apr 2022
    Posts
    65

    Re: [RESOLVED] Disable Scroll on ComboBox MouseOver

    This parse as malware.

  7. #7
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: [RESOLVED] Disable Scroll on ComboBox MouseOver

    Quote Originally Posted by mmx88_ValidUser View Post
    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
  •  



Click Here to Expand Forum to Full Width