Click here to Skip to main content
16,016,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
How to disable mouse scrolling while ContextMenuStrip is open in vb .net?

What I have tried:

I have no idea how I can achieve this
Posted
Updated 1-Jan-22 8:42am

1 solution

Hi,

ContextMenuStrip does not proved scroll event trapping, not tried this but you may be able to use IMessageFilter.PreFilterMessage and trap mouse wheel events when the ContextMenuStrip is active, there may be other conditions such as page up and page down you have to trap as well to completely block scrolling.

Private Const WM_MOUSEWHEEL As Integer = &H20A

Private ContextActiveFlag as Boolean = False

<Security.Permissions.SecurityPermissionAttribute(Security.Permissions.SecurityAction.Demand)>
    Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements IMessageFilter.PreFilterMessage
        '
        ' Manage Time Value For Idle Timeout
        '
        Select Case m.Msg
            Case WM_MOUSEWHEEL
            '
            ' If Context Menu Flag True Return True on Mouse Wheel event to ignore
            '
            If ContextActiveFlag = True Then
               Return True
            End If
        End Select
        '
        ' not handling this event so return false
        '
        Return False
    End Function


On the MenuStrip control trap the Opening or Opened to toggle the ContextActiveFlag to True and the Closing or Closed events to toggle the ContextActiveFlag to False.
 
Share this answer
 
Comments
Member 12617947 2-Jan-22 3:54am    
HI,dear Michael_Davies Thank you for your help, this is exactly what I wanted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900