看来,当使用 a 时,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
和覆盖效果不佳的滚动功能。
有谁知道如何一劳永逸地停止滚动文本框?
它不应该到顶部,也不应该到底部,当然也不应该到当前选择,而应该停留在当前位置。