4

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?

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. The questions/solutions that I have come across on SO are the following:

Scroll to bottom of 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.

Any suggestions are greatly appreciated.

2
  • 1
    Just a guess: PathText.SelectionStart = PathText.Text.Length; Commented Jun 13, 2012 at 17:15
  • You are correct; I initially copied old code that I had not compiled yet when I typed up the question. Thanks for taking a look at it. Commented Jun 13, 2012 at 17:27

2 Answers 2

4

You could do something like this:

 PathText.Focus(); PathText.Select(PathText.Text.Length, 0); 
Sign up to request clarification or add additional context in comments.

1 Comment

The problem was elsewhere in the code apparently, but I will go ahead and mark this as the answer because .Focus(); is a crucial part of the process based on the previous questions and other discussions I found from the Google searches. Thanks though!
1
textBox1.Select(textBox1.Text.Length, 0); // call focus textBox1.Focus(); 

OR

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.