title: Synchronize richtextbox scrolling in winforms
body: <p>I've used the following method </p>
  
  <p><a href="http://snipplr.com/view/50758/scroll-multiple-richtextboxes-or-textboxes-in-unison-synchronized-scrolling/" rel="nofollow">http://snipplr.com/view/50758/scroll-multiple-richtextboxes-or-textboxes-in-unison-synchronized-scrolling/</a></p>
  
  <p>to scroll two richtextboxes, I ended up with the following and just called rtb1.BindScroll(rtb2)</p>
  
  <p>This works but is it possible to support the wheelmouse for both? Also, pageup and down would be good. </p>
  
  <p>This method promised the wheelmouse but did not work at all
  <a href="http://social.msdn.microsoft.com/Forums/windows/en-US/161d1636-aea3-4fee-beb4-52370663d44c/synchronize-scrolling-in-2-richtextboxes-in-c?forum=winforms" rel="nofollow">http://social.msdn.microsoft.com/Forums/windows/en-US/161d1636-aea3-4fee-beb4-52370663d44c/synchronize-scrolling-in-2-richtextboxes-in-c?forum=winforms</a></p>
  
  <pre><code>   [DebuggerNonUserCode]
      public class RouterRichTextBox : RichTextBox
      {    
          public delegate void vScrollEventHandler(Message message);
          public const int WM_VSCROLL = 0x115;
          public event vScrollEventHandler vScroll;
  
          private List&lt;RouterRichTextBox&gt; peers = new List&lt;RouterRichTextBox&gt;();
  
          public void BindScroll(RouterRichTextBox arg)
          {
              if (peers.Contains(arg) || arg == this) 
                  return; 
              peers.Add(arg);
              arg.BindScroll(this);
          }
  
          private void DirectWndProc(ref Message m)
          {
              base.WndProc(ref m);
          }
  
          protected override void WndProc(ref Message m)
          {
              if (m.Msg == WM_VSCROLL)
              {
                  foreach (RouterRichTextBox peer in peers)
                  {
                      Message peerMessage = Message.Create(peer.Handle, m.Msg, m.WParam, m.LParam);
                      peer.DirectWndProc(ref peerMessage);
                  }
              }
  
              base.WndProc(ref m);
          }
      }
  </code></pre>