Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cancel mouse wheel scrolling in a combobox VB.NET

Cancel mouse wheel scrolling in a combobox VB.NET

Scheduled Pinned Locked Moved Visual Basic
csharphtmlcom
5 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    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)

    D 1 Reply Last reply
    0
    • M Marcus J Smith

      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)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        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)

        D 1 Reply Last reply
        0
        • M Marcus J Smith

          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)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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 the Select 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 ComboBox

          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
                      ' 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

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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 the Select 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 ComboBox

            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
                        ' 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

            M Offline
            M Offline
            Marcus J Smith
            wrote on last edited by
            #5

            I 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)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups