如何设置“|” 字符到文本框中的最后一个位置?

The*_*ask 5 .net c# textbox

在我的过滤器上,我删除了 中的无效字符textBox,但之后我删除了无效字符,即“|” 定位到第一个位置,如何设置到最后一个位置?

例如:

当前位置:

123 | 123 一个 <- 无效字符,我的函数_TextChanged将其删除并且位置转到:

| 123

我想:

123 | 123

我希望这是清楚的..提前致谢。

小智 4

将属性设置TextBox.SelectionStart为字符串末尾,并将TextBox.SelectionLength属性设置为0

像这样的东西:

int textLength = yourTextBox.Text.Length;
yourTextBox.SelectionStart = textLength;
yourTextBox.SelectionLength = 0;
Run Code Online (Sandbox Code Playgroud)