|
-
Jul 26th, 2005, 10:14 AM
#1
Thread Starter
Lively Member
[RESOLVED] Format a char from e.KeyCode etc.
I have a keydown event that looks like this
VB Code:
If e.KeyCode <> Windows.Forms.Keys.Up And e.KeyCode <> Windows.Forms.Keys.Down And e.KeyCode <> Windows.Forms.Keys.Enter Then
Me.txtSearchBox.Focus()
Me.txtSearchBox.Text = e.KeyCode.ToString
Me.txtSearchBox.SelectionStart = 1
End If
This works fine, except for when you use the number pad. For instance, if you hit '2' on the number pad, the textbox would show 'NumPad2'. I want it to just display the '2'. I have tried e.KeyCode, e.KeyData, e.KeyValue, and all of their ToString() functions, but none of them return what I want. Does anyone know how I can fix this?
Thanks for any help!
Last edited by thecow95; Jul 26th, 2005 at 12:41 PM.
-
Jul 26th, 2005, 10:45 AM
#2
Re: Format a char from e.KeyCode etc.
there may be a simpler solution, but you can simply extract the number from the keyname
VB Code:
Public Function GetNumbersInString(ByVal text As String) As String
Dim C() As Char = text.ToCharArray
Dim temp As String = String.Empty
For i As Integer = 0 To C.Length - 1
If Char.IsDigit(C(i)) Then
temp &= C(i)
End If
Next
Return temp
End Function
i actually use this function for one reason or another in just about all my apps
-
Jul 26th, 2005, 12:40 PM
#3
Thread Starter
Lively Member
Re: Format a char from e.KeyCode etc.
I was trying to find an easier way, but had no luck.
This function gets me there though, I appreciate it!
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
|