Hello, hello. It's me again. I need to know what event in a text box has the KeyAscii thingy built into it. In 6.0 I know it's the KeyPress event, but in .NET?...
Thankyou for your time.
Furry
Printable View
Hello, hello. It's me again. I need to know what event in a text box has the KeyAscii thingy built into it. In 6.0 I know it's the KeyPress event, but in .NET?...
Thankyou for your time.
Furry
I think I should rephrase this. How do you get the ASCII code for the key the user presses in a text box?
Thanks,
Furry
in the keypress even of the textbox add the following code :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar)
MsgBox(KeyAscii)
End Sub
have fun
Thanks for your reply. The code you gave me worked like a charm. :)
Furry
u r funny:p
Good. Maybe you'll find this amusing, then. :D:p I need to ask one more thing of you. How do you convert KeyAscii back into a format that e understands - like from integer to whatever e is?
Thanks,
Furry
here you go :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar) '(e.KeyChar)
MsgBox(Chr(KeyAscii))
End Sub
nightmares . oh **** , I mean night lol:o
OH!!! I see!!! e is a string! That solves ALL my problems! :D What I've been trying to do here is disable all non-numeric keys...
lolQuote:
nightmares . oh **** , I mean night lol
Thanks!
Furry
P.S.
How do you like my avatar?? :)
Oh, wait! I can't tell it to disable the keys! AARGH! Here's the code I was using back in the day of 6.0:
VB Code:
Private Sub CheckInput(ByVal KeyAscii as Integer) Dim strValid As String strValid = "0123456789" If KeyAscii > 26 Then If InStr(strValid, Chr$(KeyAscii)) = 0 Then KeyAscii = 0 End If End If End Sub -------------------------------------------------------------------------- Private Sub TextBox1_KeyPress(ByVal KeyAscii as Integer) CheckInput KeyAscii End Sub
How would I do this in .NET?
(well, I really like handling keyascii problems)
take this :
Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar)
'only allow numbers, a single decimal point, backspace or enter
Select Case KeyAscii
Case Asc("0") To Asc("9"), Asc(ControlChars.Back)
'acceptable keys
e.Handled = False
Case Asc(ControlChars.Cr)
'enter key - move to next box
txtInterest.Focus()
e.Handled = False
Case Asc(".")
'check for existance of decimal point
If InStr(txtDeposit.Text, ".") = 0 Then
e.Handled = False
Else
e.Handled = True
End If
Case Else
e.Handled = True
End Select
I know you will face problems ,
cheers:p
This allows only numbers and backspace to work in a textbox.
Code:Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim I As Integer = Convert.ToInt32(e.KeyChar)
If Not (System.Char.IsNumber(e.KeyChar)) Then
If I <> 8 Then
e.Handled = True
End If
End If
End Sub
*In a piratish voice*
Arr!! Thankye, pirate! The code worked swell, with no bugs, unlike ye thought. :) About ye color-coding with text, ye only use the vbcode tags. Yeargh. It's the least aye can do for ye's, considering ye have helped me greatly in my quest for knowledge. Yeargh.
Thankye!
Arrgh and piraty stuff...
[edit]
Just saw ye post, hellswraith. Thankye kindly also!
[/edit]
Furry
Code:Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar)
'only allow numbers, a single decimal point, backspace or enter
Select Case KeyAscii
Case Asc("0") To Asc("9"), Asc(ControlChars.Back)
'acceptable keys
e.Handled = False
Case Asc(ControlChars.Cr)
'enter key - move to next box
txtInterest.Focus()
e.Handled = False
Case Asc(".")
'check for existance of decimal point
If InStr(txtDeposit.Text, ".") = 0 Then
e.Handled = False
Else
e.Handled = True
End If
Case Else
e.Handled = True
End Select
Ahh! Thanks again!
Furry
then it must be written at the top & the end
thanx anyway for this help
try thinkin about hotkeys for your app.night