滚动到C#中单行文本框的末尾

时间:2012-06-13 17:11:36

标签: c# .net winforms

关于单行文本框(Multiline属性设置为false),当文本长度超过框的水平大小时,是否可以滚动到行尾??

我尝试过各种适用于多线盒的解决方案,但到目前为止它们都没有用过。

过去曾有几个人提出过非常类似的问题,但它一直都认为是多行文本框。我在SO上遇到的问题/解决方案如下:

Scroll to bottom of C# TextBox

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

现在我有以下代码(看似不起作用):

PathText.Text = "";
PathText.AppendText(BrowseDialog.SelectedPath);
PathText.SelectionStart = PathText.TextLength;
PathText.ScrollToCaret();
PathText.Refresh();

PathText是正在使用的文本框,BrowseDialog是FileDialog。

非常感谢任何建议。

2 个答案:

答案 0 :(得分:1)

你可以这样做:

 PathText.Focus();
 PathText.Select(PathText.Text.Length, 0);

答案 1 :(得分:1)

textBox1.Select(textBox1.Text.Length, 0);
// call focus 
textBox1.Focus();

OR

textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox1.Focus();
相关问题