JumpyNET Posted December 17, 2007 Posted December 17, 2007 What is the shortest way to check if a pressed key is alphanumeric in a KeyDown event? PS: I'm using VB2005 Express. Quote
Administrators PlausiblyDamp Posted December 17, 2007 Administrators Posted December 17, 2007 I've just tended to check with Char.IsLetterOrDigit Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JumpyNET Posted December 17, 2007 Author Posted December 17, 2007 I've just tended to check with Char.IsLetterOrDigit Ok, I tried this: Private Sub MyControl_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Lista.KeyDown Dim PressedChar As Char = Chr(e.KeyCode) If Char.IsLetterOrDigit(PressedChar) Then MsgBox("You pressed: " & PressedChar) End If End Sub Odly the IsLetterOrDigit is true if I press any of the F#-keys. Can you suggest some other conversion method from key to char? Quote
Administrators PlausiblyDamp Posted December 17, 2007 Administrators Posted December 17, 2007 I would use the KeyPress event rather than the KeyUp / Down as you get the actual character with the press event. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JumpyNET Posted December 17, 2007 Author Posted December 17, 2007 I would use the KeyPress event rather than the KeyUp / Down as you get the actual character with the press event. Rigth. Thank you. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.