简体   繁体   English

Richtextbox-仅在滚动条位于底部时滚动

[英]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. 我有一个RichTextBox,它随每个AppendText一起滚动,但只有在滚动条位于底部时才滚动。 I would like for example to easily select and copy something from the middle of the richtextbox while text is appended to the RichTextBox. 例如,我想在文本附加到RichTextBox的同时轻松地从richtextbox的中间选择并复制内容。 Tried many solutions, but nothing really worked correct. 尝试了许多解决方案,但没有任何真正可行的方法。 Is this even possible? 这有可能吗?

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): 例如(未经测试,假设使用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. 对我来说,这似乎是预期的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM