看来,使用时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
,并覆盖了滚动功能,没有工作这么好。
有谁知道如何,一劳永逸,停止文本框的滚动?
它不应该去顶,既不是底,当然也不会在当前选择,而只是留在当前的时刻。