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?
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 ...
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?
Create your own class that derives from RichTextBox and try one of two things:
- 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.
- 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); } }
WndProc, yes what a good idea. Thanks a lot.