Capture Keys in Textbox, VB.net 2005:
I'm working on learning VB.Net, using 2005,
In VB 6, when you use a textbox:
Private Sub txtPv_KeyPress(Index As Integer, KeyAscii As Integer)
'If the ENTER is pressed, then call the function to set the PV.
If KeyAscii = 13 Then
Call cmdSetPv_Click(Index)
End If
End Sub
However, with VB.Net, when I select the "KeyPress" I get:
PrivateSub TextBox1_KeyPress(ByVal senderAsObject,ByVal eAs System.Windows.Forms.KeyPressEventArgs)Handles TextBox1.KeyPress
EndSub
I can't figure out how to capture the keys that were pressed using the arguments to the TextBox1_KeyPress Sub.
All of the help that I can find tells me that the "KeyPress" is as:
PrivateSub Text1_KeyPress(KeyAsciiAsInteger)
What am I missing?
Mfroster
[2222 byte] By [
mfroster] at [2007-12-22]
I think its pretty similar to you vb6 process, although i use Keydown, intead of Keypress (someone who knows could explain why you would use one instead of the other)
I think the keypress event uses e.keychar instead of e.keyvalue
Ie
Private Sub FrmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDownIf e.KeyValue = Keys.Tab Then...
Else
....
End If
End SubOr you could use a select case statement similar to
Select Case e.keyvalue
Case 9 ' 9 = Tab
...
Case 13 ' 13 = Enter
...
End Select
Hope That helps you somehow :)
I have found that using a chr() works with e.keychar. for instance:
Private Sub frmGame_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles frmGame.KeyPress
If e.KeyChar = Chr(65) then 'Chr(65) = A
lblLetterDisplay.text = A
else
bah
end if
end sub
RDT at 2007-8-30 >
