lowercase to uppercase

atesh

Active member
Joined
Aug 2, 2003
Messages
41
Location
Washington State, USA
whats the code at the keypress event thatll make a pressed lowercase letter uppercase. here is what tried, which obviously doesnt work but you get the idea:
Code:
    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
 
heres what i did which works:
Code:
        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 dont have to manually convert them :-).
 
You shouldnt 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.
 

Similar threads

Back
Top