问题描述
我有一个C#窗体应用程序一个TextBox。我填充在窗体的Load事件信息的文本框。然后,我打电话以下内容:
I have a TextBox on a C# Forms Application. I populate the TextBox with information on the Load event of the form. I then call the following:
this.txtLogEntries.SelectionStart = txtLogEntries.Text.Length;
this.txtLogEntries.ScrollToCaret();
然而,文本框不滚动到底?
However the TextBox does not scroll to the bottom ?
这仅适用于Load事件虽然。一旦它的运行我也更新从应用程序的其他部分这个文本框,并尽快这些事件更新的文本框,它被滚动到下一个。
This only applies to the Load event though. I also update this TextBox from other parts of the application once it's running, and as soon as one of these events update's the TextBox, it is scrolled to the bottom.
所以, ,我怎样才能得到它的预填充在窗体的Load事件的文本框时滚动到底?
So, how can I get it to scroll to the bottom when pre populating the TextBox in the Form Load event?
推荐答案
尝试把在表单代码的显示的事件:
Try putting the code in the Form's Shown event:
private void myForm_Shown(object sender, EventArgs e)
{
txtLogEntries.SelectionStart = txtLogEntries.Text.Length;
txtLogEntries.ScrollToCaret();
}
这篇关于滚动到C#文本框的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!