我有一个RichTextBox,当新的文本被添加时,我希望它自动滚动到文本的末尾。
这是我的代码:
private void outputWindowTextChanged(object sender, EventArgs e) {
rtb_outputWindow.SelectionStart = rtb_outputWindow.Text.Length;
rtb_outputWindow.ScrollToCaret();
}
我手动向RichTextBox添加了一些文本,就像这样:
updateOutputWindow("Lorem ipsum dolor sit amet, ..."); //These strings are really long
updateOutputWindow("Lorem ipsum dolor sit amet, ..."); //I shortened them for this question
这是结果:
在上面的截图中,你可以勉强看出边缘下方实际上还有更多文本。你也可以查看右侧的滚动条,看到底部还留有一点空间。
在上面的截图中,我手动使用右侧的滚动条向下滚动到底部,揭示了之前隐藏的文本。
是否有一种方法可以确保 RichTextBox 每次自动滚动到最末端?
updateOutputWindow
之后。 - Timothy Grootertb_outputWindow.HideSelection = false;
然后使用AppendText
将新行添加到文本框中吗?(这应该也会自动滚动文本框) - Timothy Groote