【发布时间】:2012-09-29 00:27:24
【问题描述】:
似乎在使用System.Windows.Forms.RichTextBox 时,您可以使用textbox.AppendText() 或textbox.Text = "" 向文本框添加文本。
AppendText 会滚动到底部,直接添加文本不会滚动,但是当用户聚焦文本框时会跳转到顶部。
这是我的功能:
// Function to add a line to the textbox that gets called each time I want to add something
// console = textbox
public void addLine(String line)
{
// Invoking since this function gets accessed by another thread
console.Invoke((MethodInvoker)delegate
{
// Check if user wants the textbox to scroll
if (Settings.Default.enableScrolling)
{
// Only normal inserting into textbox here with AppendText()
}
else
{
// This is the part that doesn't work
// When adding text directly like this the textbox will jump to the top if the textbox is focused, which is pretty annoying
Console.WriteLine(line);
console.Text += "\r\n" + line;
}
});
}
我也尝试过导入 user32.dll 并覆盖效果不佳的滚动功能。
有人知道如何一劳永逸地停止滚动文本框吗?
它不应该到顶部,也不应该到底部,当然也不应该到当前选择,而应该停留在当前位置。
【问题讨论】:
标签: c# scroll richtextbox