0

我可以手动完成,但是如何从我的代码中设置它,所以当我将焦点放在文本框上时,键盘将允许用户开始输入大写字母?

4

3 回答 3

1

认为您不会强制它全部为大写,而是对他们在可能的解决方案中键入的值执行 .ToUpper() 吗?

于 2010-12-03T16:35:30.830 回答
1

这种方式更好:

private void codeTextChanged(object sender, TextChangedEventArgs e)
{
    tPCodeText.Text = (sender as TextBox).Text.ToString().ToUpper();
    tPCodeText.SelectionStart++;
}
于 2011-08-17T20:16:52.267 回答
0

您必须使用 TextChanged 事件。

private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
    // Save cursor's position
    int cursorLocation = textBox1.SelectionStart;

   // Uppercase text
   textBox.Text = textBox1.Text.ToUpper();

   // Restore cursor's position
   textBox.SelectionStart = cursorLocation;
} 

资源

于 2010-12-03T16:57:47.813 回答