Hi,
In vb6, we can use KeyAscii = Asc(UCase(Chr(KeyAscii))) in the keypress event to convert any char into its uppercase when the key is pressed.
How to do this in vb.Net?
Please give me a help.
Thanks,
James
Printable View
Hi,
In vb6, we can use KeyAscii = Asc(UCase(Chr(KeyAscii))) in the keypress event to convert any char into its uppercase when the key is pressed.
How to do this in vb.Net?
Please give me a help.
Thanks,
James
Try e.keychar = UCase(e.keychar).
I use e.keychar to check if a keychar = some value, but haven't tried this out.
Hi salvelinus
It give me error message : keychar is read only.
Any help?
Thanks,
James
If you want all of the text uppercase then you can use TextBox1.Text=TextBox1.Text.ToUpper which you could run in the KeyPress or in Validate. I believe the Char type has a ToUpper method as well so this would probably work too; e.keychar.ToUpper.
I've used this before for a mobile app. It works fine, but right now I can't remember why I had to set the position and handled etc. - maybe it's not the best code...
VB Code:
Private Sub TextBoxDOB_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxDOB.KeyPress If e.KeyChar.IsLower(e.KeyChar) Then ' Save current location Dim pos As Integer = TextBoxDOB.SelectionStart TextBoxDOB.Text = TextBoxDOB.Text & e.KeyChar.ToUpper(e.KeyChar) TextBoxDOB.SelectionStart = pos + 1 e.Handled = True End If End Sub
If you're using a TxtBox there is a property that puts all the letters in uppercase
You're right, CharacterCasing is the property. FWIW, this property is not available in the Compact Framework, hence my funky work-around.