简体   繁体   English

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

[英]Scroll to the end of a Single-Line Textbox in C#

In regards to single-line textboxes (Multiline property is set to false), is it possible to scroll to the end of the line when the text length exceeds the horizontal size of the box? 对于单行文本框(Multiline属性设置为false),当文本长度超过框的水平大小时,是否可以滚动到行尾?

I have tried various solutions that work for multi-line boxes, but none of them have worked thus far. 我尝试过各种适用于多线盒的解决方案,但到目前为止它们都没有。

Very similar questions have been asked by several individuals in the past, but it has always regarded Multi-Line textboxes. 过去曾有几个人提出过非常类似的问题,但它一直都认为是Multi-Line文本框。 The questions/solutions that I have come across on SO are the following: 我在SO上遇到的问题/解决方案如下:

Scroll to bottom of C# TextBox 滚动到C#TextBox的底部

How do I automatically scroll to the bottom of a multiline text box? 如何自动滚动到多行文本框的底部?

Right now I have the following code (which seemingly does not work): 现在我有以下代码(似乎不起作用):

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

PathText is the textbox in use, and BrowseDialog is a FileDialog. PathText是正在使用的文本框, BrowseDialog是FileDialog。

Any suggestions are greatly appreciated. 任何建议都非常感谢。

You could do something like this: 你可以这样做:

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

OR 要么

textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox1.Focus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM