.net - How to select text in a TextBox with the caret positioned at the START of the selection? -


I am using a System.Windows.Forms.TextBox . It is possible to choose text using the keyboard in such a way that the carat selection is positioned on the start - by moving and moving the careet to the left.

I want to do the same programmatically. For example, suppose I have a text box with "some sample text" text. I'd like to select the word "sample", and I would like to prepare for the carat just before "s" in "sample".

If I do this:

  Textbox SelectionStart = 5; Textbox.SelectionLength = 6;  

Then I get the selected word, but the carat is only after "e" in "sample".

If I do this:

  textbox.SelectionStart = 11; Textbox.SelectionLength = -6;  

I get an exception.

How can I keep care in the beginning of the selection?

I am not able to program. As stated in the original window controls, displays a shining caret in the last position regardless of the relative values ​​of the start and end.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -