|
-
Oct 17th, 2002, 10:00 AM
#1
Thread Starter
Addicted Member
KeyAscii
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
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 03:22 PM
#2
Thread Starter
Addicted Member
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
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 05:38 PM
#3
Sleep mode
resolved
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
Last edited by Pirate; Oct 17th, 2002 at 05:48 PM.
-
Oct 17th, 2002, 05:55 PM
#4
Thread Starter
Addicted Member
Thanks for your reply. The code you gave me worked like a charm. 
Furry
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 05:56 PM
#5
-
Oct 17th, 2002, 06:06 PM
#6
Thread Starter
Addicted Member
Good. Maybe you'll find this amusing, then.  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
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 06:13 PM
#7
Sleep mode
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
-
Oct 17th, 2002, 06:19 PM
#8
Thread Starter
Addicted Member
OH!!! I see!!! e is a string! That solves ALL my problems! What I've been trying to do here is disable all non-numeric keys...
nightmares . oh **** , I mean night lol
lol
Thanks!
Furry
P.S.
How do you like my avatar??
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 06:26 PM
#9
Thread Starter
Addicted Member
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?
Last edited by Fat_N_Furry; Oct 17th, 2002 at 06:30 PM.
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 06:29 PM
#10
Sleep mode
(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
-
Oct 17th, 2002, 06:31 PM
#11
PowerPoster
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
-
Oct 17th, 2002, 06:38 PM
#12
Thread Starter
Addicted Member
*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
Last edited by Fat_N_Furry; Oct 17th, 2002 at 06:41 PM.
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 06:42 PM
#13
Sleep mode
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
-
Oct 17th, 2002, 06:44 PM
#14
Thread Starter
Addicted Member
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Oct 17th, 2002, 06:44 PM
#15
Sleep mode
then it must be written at the top & the end
thanx anyway for this help
-
Oct 17th, 2002, 06:46 PM
#16
Sleep mode
try thinkin about hotkeys for your app.night
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
|