|
-
Sep 26th, 2002, 08:33 AM
#1
Thread Starter
Registered User
keypress event question
I have a question, lets say i have the following
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "=" Then
MsgBox("You Pressed "="")
End If
End Sub
how can i do the same thing with enter? if anyone knows how to do this, i would greatly appreciate it.
thanks,
Last edited by jkw119; Sep 26th, 2002 at 08:56 AM.
-
Sep 26th, 2002, 09:37 AM
#2
Member
Hi
The only way I could get this working is using the Keydown event.
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Select Case e.KeyCode
Case Keys.Enter
MessageBox.Show("You pressed Enter")
End Select
End Sub
Harold Hoffman
-
Sep 26th, 2002, 11:07 AM
#3
Fanatic Member
Code:
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
MsgBox("pressed enter!")
End If
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWindowsFormsKeyPressEventArgsClassKeyCharTopic.htm
Somewhere buried in the help is also a nice table of which ASCII/Unicode numbers correspond to keys/characters also.
This also works:
Code:
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
MsgBox("pressed enter!")
End If
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWindowsFormsKeysClassTopic.htm
ps: duh, both on the KeyPress event, not KeyDown
Last edited by Slow_Learner; Sep 26th, 2002 at 11:11 AM.
-
Sep 26th, 2002, 07:37 PM
#4
Lively Member
Are you wanting to move to another control when the enter key is pressed on the keypressed event?, is that what you are asking?
If so, this below works.
Code:
Private Sub txtDataFormat_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDataFormat.KeyPress
'Ceck if enter was pressed
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
'Is this textbox active or not?
If (Me.txtDisplay.Enabled = True) Then
'Ok go here then
Me.txtDisplay.Focus()
Else
'No it's not so move to the command button instead
Me.cmdClose.Focus()
End If
End If
End Sub
Hope that helps.
-
Sep 26th, 2002, 10:53 PM
#5
Sleep mode
another way
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim ky As Integer
ky = Asc(e.KeyChar)
Select Case ky
Case Asc(ControlChars.Cr)
TextBox2.Focus()
e.Handled = False
End Select
End Sub
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
|