简体   繁体   中英

how to set the “|” character to last position in textBox?

on my filter, I remove invalid characters in my textBox , but after that I removed invalid characters, the "|" is positioned into first position,how can I to set to last position?

For example:

current position:

123 | a <- invalid character, my function in the _TextChanged event remove it and the position go to:

| 123

I want:

123 |

I hope this is clear.. Thanks in advance.

Set the TextBox.SelectionStart property to the end of the string, and the TextBox.SelectionLength property to 0 .

Something like this:

int textLength = yourTextBox.Text.Length;
yourTextBox.SelectionStart = textLength;
yourTextBox.SelectionLength = 0;

You need to set the SelectionStart to the current text length. In VB, this is:

txtStatus.SelectionStart = txtStatus.Text.Length

If this is a multi-line textbox or if the text exceeds the visible width of the textbox, you also may need to scroll the selection point into view:

txtStatus.ScrollToCaret()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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