Sunday, 15 April 2012

.net - C#: Synchronize Scroll Position of two RichTextBoxes? -


As my application, I have two RichTextBox objects both of the lines of text In the same number, I want to "synchronize" the vertical scrolling between the two, so that when the user changes the vertical scrolling position on one, how can I go about doing the same amount of other scrolls?

Some time ago I did a small project, and I found the simplest solution here

Create a new control by subclassing the rich textbox:

  Synchronize public class ScrollRichTextBox: System.Windows.Forms.RichTextBox {public event vScrollEventHandler vScroll; Public representative Zero vScrollEventHandler (System.Windows.Forms.Message Message); Public const int WM_VSCROLL = 0x115; Protected Override Zero WndProc (Ref System. Windows.Forms.Message Message) {if (msg.Msg == WM_VSCROLL) {if (vScroll! = Null) {vScroll (msg); }} Base.WandProc (Riff Message); } Public Zero PubWndProc (Ref System. Windows.Forms.Message msg) {base.WndProc (Riff Message); }}  

Add new control to your form and clearly inform other instances of control for each control that its vScroll status has changed. Something like this:

  Private Zero scrollSyncTxtBox1_vScroll (Message msg) {msg.HWnd = scrollSyncTxtBox2.Handle; ScrollSyncTxtBox2.PubWndProc (Riff Message); }  

I think there are problems in this code if all 'link' controls do not have the same number of displaylines.


No comments:

Post a Comment