Search code examples
c#winformstextbox

How to always show end of text in windows form textbox c# (even when not focused)


CONTEXT :

  • I'm using visual studio 2017 on a win 10 computer.
  • I'm developing a C# windows form app.
  • The app saves files to a directory. (Here pictures and videos)
  • You can select the wanted folder with a button. ([...])
  • The selected folder's path then shows in the textbox.
  • The textbox is always set to disabled. (I want the user to always go through the FolderBrowserDialog to select the desired folder)

QUESTION :

I want the textbox to always show the end of my selected folder's text even when not in focus.

enter image description here

enter image description here

I'm limited in space and can't stretch the textbox to show all the path.

Here, I would like the textbox to show something like :

...\morneaulo\Desktop instead of C:\Users\morneaulo\Des...

I would also prefer to keep all the available text in the textbox because I use the textbox.Text property when the files are saved.


Solution

  • You could try to set it in code behind like so:

    FileTextBox.SelectionStart = FileTextBox.Text.Length;
    FileTextBox.SelectionLength = 0;