lowercase to uppercase

atesh

Freshman
Joined
Aug 2, 2003
Messages
41
Location
Washington State, USA
what's the code at the keypress event that'll make a pressed lowercase letter uppercase. here is what tried, which obviously doesn't work but you get the idea:
Visual Basic:
    Private Sub TextBox_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox.KeyPress
        If e.KeyChar.IsLower(e.KeyChar) Then e.KeyChar = e.KeyChar.ToUpper(e.KeyChar)
    End Sub
 
here's what i did which works:
Visual Basic:
        If e.KeyChar.IsLower(e.KeyChar) Then
            e.Handled = True
            TextBox.Text &= e.KeyChar.ToUpper(e.KeyChar)
            SendKeys.Send("{END}")
        End If
The pressing END key is so the caret is at the end of the textbox instead of the start.
 
You can also set the text box properties to upper case then all characters appear in the box will be upper. You don't have to manually convert them :-).
 
You shouldn't simply concatenate the key pressed, since the caret could be in the middle of the textbox. Set the CharacterCasing property to Upper, as that will handle pasting text as well.
 
Back
Top