Disable RichTextBox mouse wheel

This is a discussion on Disable RichTextBox mouse wheel within the C# Programming forums, part of the General Programming Boards category; When a RichTextBox has focus, it will naturally scroll vertically when the mouse wheel is turned. Is it possible to ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209

    Disable RichTextBox mouse wheel

    When a RichTextBox has focus, it will naturally scroll vertically when the mouse wheel is turned. Is it possible to disable this feature? I was hoping for a Suppress option in the MouseWheel event arguments but no joy. Any ideas?

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Create your own class that derives from RichTextBox and try one of two things:

    1. Override OnMouseWheel() and do not call base.OnMouseWheel(). Unfortunately, I don't think any processing actually happens in the OnMouseWheel() method aside from firing events, so this probably won't solve your problem.
    2. Override WndProc and handle the WM_MOUSEWHEEL message yourself. Make sure you pass all other messages to base.WndProc(). I'd say this has a good probability of solving your problem.


    For #2, something like this should work:
    Code:
    public class NoScrollRichTextBox : RichTextBox
    {
       const int WM_MOUSEWHEEL = 0x020A;
    
       protected override void WndProc(ref Message m)
       {
          // This will completely ignore the mouse wheel, which will disable zooming as well
          if (m.Msg != WM_MOUSEWHEEL)
             base.WndProc(ref m);
       }
    }

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    WndProc, yes what a good idea. Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disable mouse scroll wheel - how?
    By ulillillia in forum Tech Board
    Replies: 15
    Last Post: 04-16-2009, 09:12 AM
  2. my mouse wheel
    By DavidP in forum Tech Board
    Replies: 0
    Last Post: 11-06-2006, 09:58 AM
  3. Problems with mouse wheel...
    By xkrja in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2006, 03:22 PM
  4. Mouse Wheel In Console
    By GaPe in forum C Programming
    Replies: 0
    Last Post: 09-07-2002, 03:05 AM
  5. How to disable a mouse in a console
    By GaPe in forum C Programming
    Replies: 7
    Last Post: 05-26-2002, 06:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21