I would like to change all the characters entered into a textbox to upper case. The code will add the character, but how do I move the caret to the right?
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
textBox3.Text += e.KeyChar.ToString().ToUpper();
e.Handled = true;
}
Set the
CharacterCasingproperty of theTextBoxtoUpper; then you don’t need to process it manually.Note that
textBox3.Text += e.KeyChar.ToString().ToUpper();will append the new character to the end of the string even if the input caret is in the middle of the string (which most users will find highly confusing). For the same reason we cannot assume that the input caret should appear at the end of the string after inputting the character.If you would still really want to do this in code, something like this should work: