简体   繁体   English

如何将“|”字符设置为textBox中的最后位置?

[英]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 "|" 在我的过滤器上,我删除了我的textBox中的无效字符,但之后我删除了无效字符,“|” is positioned into first position,how can I to set to last position? 位于第一位置,我该如何设置到最后位置?

For example: 例如:

current position: 当前位置:

123 | 123 | a <- invalid character, my function in the _TextChanged event remove it and the position go to: 一个< - 无效字符,我在_TextChanged事件中的函数将其删除,并且位置转到:

| | 123 123

I want: 我想要:

123 | 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 . TextBox.SelectionStart属性设置为字符串的末尾,将TextBox.SelectionLength属性设置为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. 您需要将SelectionStart设置为当前文本长度。 In VB, this is: 在VB中,这是:

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()

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

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