C# 如何在 WinForms 中制作自动滚动多行文本框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13505248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:47:16  来源:igfitidea点击:

How to make autoscroll multiline TextBox in WinForms?

c#.netwinformstextbox

提问by Ivan

Possible Duplicate:
How do I automatically scroll to the bottom of a multiline text box?

可能的重复:
如何自动滚动到多行文本框的底部?

I use a multiline TextBoxto output some information in new lines as it arrives from a BackgroundWorker.

我使用多TextBox行在新行中输出一些信息,因为它从BackgroundWorker.

Can I make it to scroll to the very bottom each time a new line arrives?

每次有新行到达时,我可以让它滚动到最底部吗?

By default it seems to do just the opposite - it scrolls to the very first line each time a new line arrives and the Textproperty is changed.

默认情况下,它似乎正好相反 - 每次新行到达并Text更改属性时,它都会滚动到第一行。

采纳答案by patrick choi

Set the TextBoxproperties:

设置TextBox属性:

Multiline = True;
ScrollBars = Both;

To auto scroll on the TextChangedevent:

要自动滚动TextChanged事件:

textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();