Shelly Tomar
Shelly Tomar

Reputation: 195

Add 1 scrollbar for 2 richtextboxes in winforms

I want to add a scrollbar which can be used for both these richtextboxes in winforms so that when i scroll down, the text in these boxes goes down. Right now, both have different scrollbars. I have tried the following methods which didn't work:

  1. Set autoscroll property to true in the tablelayoutpanel in which these richtextboxes are present.
  2. Set autoscroll property to true in the normal panel in which these richtextboxes are present.

enter image description here

Upvotes: 0

Views: 1010

Answers (2)

Gleb
Gleb

Reputation: 1432

You can do like @szataniel write. For this, and scroll bar control on your form, set richTextBoxes property ScrollBar=None or SrollBar=Horizontal.

And then add code like this:

    private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
        richTextBox1.SelectionStart = e.NewValue;
        richTextBox1.ScrollToCaret();
        richTextBox2.SelectionStart = e.NewValue;
        richTextBox2.ScrollToCaret();
    }

Also there is another variant. You can create your own RichTextBox class extands RichTextBox with synhroniztion methods like in the post by link

Upvotes: 0

Maciej S.
Maciej S.

Reputation: 760

You can disable scrollbars on your RichTextBox controls and add some VScrollBar control on the right or left. Please reference to MSDN description of this control: VScrollBar on MSDN

Upvotes: 1

Related Questions