I have a RichTextBox and it scrolls with every AppendText, but it shall only scroll if the scrollbar is at bottom. I would like for example to easily select and copy something from the middle of the richtextbox while text is appended to the RichTextBox. Tried many solutions, but nothing really worked correct. Is this even possible?
1 Answer
It depends how you are Appending, but you can tell it to focus back to where the selection (or just cursor) is after appending.
eg (untested, assuming WinForms):
int selStart = rtb.SelectionStart int selLength = rtb.SelectionLength rtb.AppendText("test") rtb.SelectionStart = selStart rtb.SelectionLength = selLength That will always push the selection back to where it was before the append - but won't scroll down if it was at the bottom previously. To me, that seems like expected behaviour.
5 Comments
PhazBlue
I tried that, but this solution did many mistakes. e.g. -You can't scroll, if you have something selected. -If you haven't selected anything and click at the bottom of the text the cusor goes up until it reaches the top. Now if more text is appended, it is not visible until you scroll again.
PhazBlue
I would say the behavior of the skype textbox is the textbox behavior i need.
simonalexander2005
then you need to get the position of the scrollbar itself. Look into Scrollviewers.
PhazBlue
It seems that scrollviewers are only available for WPF. I'm bound to WinForms, because i use KryptonForms.
simonalexander2005
ok, well I'll leave it to others more knowledgeable to try and help then!