0
votes

I want to use the mouse middle button to clear a RichTextBox, but it also activates a mouse scrolling functionality similar to what you find in web broswers. When the vertical scrollbar is visible (there's enough data) and you press the middle button in the mouse a scrolling cursor appears and you can scroll up or down by moving the cursor up or down. How do I disable the mouse scrolling?

Mouse scrolling seems to be a Windows (or mouse driver) feature, so how can I stop the MouseDown event (if the mouse middle button is pressed) from reaching whatever routine is responsible for the mouse scrolling?

2

2 Answers

1
votes

Check for 0x207 and 0x208, middle button down and up:

using System;
using System.Windows.Forms;

class MyRtb : RichTextBox {
    protected override void WndProc(ref Message m) {
        if (m.Msg == 0x207) this.Clear();
        else if (m.Msg != 0x208) base.WndProc(ref m);
    }
}
1
votes

No scrolling RichTextBox, just Inherit from RichTextBox and you done.

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);
   }
}