8

How can I do that if I append some text the RTB will automatically scroll down?

Now I'm using:

conversationRtb.Rtf = tab.conversationRtb.Rtf;
conversationRtb.SelectionStart = conversationRtb.Text.Length;
conversationRtb.ScrollToCaret();

But it isn't working well. Sometimes it doesn't scroll to end but one line before end.

rtb scroll down bug

Sometimes it makes a big offset.

rtb scroll down bug

I cannot find why. Is there any another way how to scroll down? I've found AutoScrollOffset but no examples how it works.

sczdavos
  • 2,035
  • 11
  • 37
  • 71
  • 3
    These two posts might help. They use `User32.dll` to scroll instead. http://stackoverflow.com/questions/8535102/inconsistent-results-with-richtextbox-scrolltocaret http://www.dutton.me.uk/2011/08/31/richtextbox-scrolltocaret-bug/ – keyboardP Oct 05 '12 at 15:25
  • I'd rather don't use user32.dll. I'm using mono and I've problems with external libraries. – sczdavos Oct 05 '12 at 15:37
  • Ok. I've just add condition. If Windows do @keyboardP solution else do default ScrollToCaret. Seems to works fine. – sczdavos Oct 19 '12 at 15:04
  • The "dutton.me.uk" link in the comment from @keyboardP seems broken, but here's a working equivalent: http://www.dutton.me.uk/2011-08-31/richtextbox-scrolltocaret-bug/ ( notice that the slashes are now hyphens in the URL ). ;-) – bernz Jul 20 '17 at 13:11

1 Answers1

8

You can adjust HideSelection value to false, the AppendText will trigger the correct scroll.

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51