usingSystem.Windows.Forms; Public classsynchronizedscrollrichtextbox:system.windows.forms.richtextbox{ PublicSynchronizedscrollrichtextbox Synchronized {Get;Set; } Public Const intWm_vscroll =0x115; Public Const intEm_linescroll =0xb6; protected Override voidWndProc (refSystem.Windows.Forms.Message msg) { if(Msg. MSG = = Wm_vscroll | | Msg. MSG = =em_linescroll) { if(Synchronized! =NULL) {Message message=msg; Message. HWnd=Synchronized.handle; Synchronized.pubwndproc (refmessage); } } Base. WndProc (refmsg); } Public voidPubwndproc (refSystem.Windows.Forms.Message msg) { Base. WndProc (refmsg); }}
The above code, copied into the project, compiled once, dragged onto the form, for example, drag 2 instances, and then set the Synchronized property to each other in the design interface. The two text boxes can be scrolled synchronously after running.
RichTextBox controls that support synchronous scrolling