|
-
Dec 29th, 2003, 02:04 PM
#1
Thread Starter
Member
how to convert into Upper case in keypress event
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
-
Dec 29th, 2003, 02:08 PM
#2
Frenzied Member
Try e.keychar = UCase(e.keychar).
I use e.keychar to check if a keychar = some value, but haven't tried this out.
-
Dec 29th, 2003, 02:17 PM
#3
Thread Starter
Member
It doesn't work
Hi salvelinus
It give me error message : keychar is read only.
Any help?
Thanks,
James
-
Dec 29th, 2003, 02:18 PM
#4
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.
-
Dec 29th, 2003, 03:19 PM
#5
Frenzied Member
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
-
Dec 30th, 2003, 07:51 AM
#6
yay gay
If you're using a TxtBox there is a property that puts all the letters in uppercase
\m/  \m/
-
Dec 30th, 2003, 10:16 AM
#7
Frenzied Member
You're right, CharacterCasing is the property. FWIW, this property is not available in the Compact Framework, hence my funky work-around.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|