0

I have a chat form with a few richtextboxes. One of them is for the messages. How can I autoScroll it when text is added to it, only if the scrollbar was at the bottom before the text was added?

I searched about my problem, but I couldn't find a clear answer.

To add the text I am using string concatenation:

rtb.Text += string.Format("\n\n{0}: {1}", newMessage, name);
Dani
  • 719
  • 1
  • 7
  • 14
  • `rtb.AppendText(string.Format("\n\n{0}: {1}", newMessage, name));` – LarsTech Jun 21 '19 at 18:54
  • @LarsTech I will use it, but I still have the scrolling problem (this method doesn't scroll the text box). – Dani Jun 21 '19 at 19:14
  • You could always add a `rtb.ScrollToCaret();` if it's not auto-scrolling. – LarsTech Jun 21 '19 at 19:19
  • Or `richTextBox1.SelectionStart = richTextBox1.TextLength;` – Jimi Jun 21 '19 at 19:22
  • @LarsTech I don't want that it will always scroll to textbox. It should scroll it only if the scrollbar was at the bottom before the text was added. – Dani Jun 21 '19 at 19:30
  • 1
    See [Get current scroll position from rich text box control?](https://stackoverflow.com/a/10238729/719186) – LarsTech Jun 21 '19 at 19:34

0 Answers0