PhazBlue
PhazBlue

Reputation: 79

Richtextbox - scroll only if scrollbar is at bottom

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?

Upvotes: 1

Views: 274

Answers (1)

simonalexander2005
simonalexander2005

Reputation: 4577

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.

Upvotes: 0

Related Questions