Event of Enter Key

  • Thread starter Thread starter portCo
  • Start date Start date
P

portCo

Hello there,

I am using Visual Basic 2005. I want to store a value when I press
enter key on the keyboard.

Could anyone help me out?


Thanks alot.
 
portCo said:
Hello there,

I am using Visual Basic 2005. I want to store a value when I press
enter key on the keyboard.

Could anyone help me out?


You should use Google and look-up how to use the Form and Controls Keyup
Keypress, and Keydown events. All of that should also be explained in VS
2005 Help with examples too.
 
You should use Google and look-up how to use the Form and Controls Keyup
Keypress, and Keydown events. All of that should also be explained in VS
2005 Help with examples too.

Or if you wanted a quick and dirty solution - just add a button and
make it the accept button for the form and add your logic to it's
button_click event. Then any time a user hits enter it will fire the
click event and process your logic. Though, if you want to only store
values from the enter key being pressed (and not allow the user to
manually press the button) then I would go with one of the 3 key
events mentioned previously.

Thanks,

Seth Rowe
 
rowe_newsgroups said:
Or if you wanted a quick and dirty solution - just add a button and
make it the accept button for the form and add your logic to it's
button_click event. Then any time a user hits enter it will fire the
click event and process your logic. Though, if you want to only store
values from the enter key being pressed (and not allow the user to
manually press the button) then I would go with one of the 3 key
events mentioned previously.

In heavy data entry solutions, I like to use the Enter-Key on a form's
control in the control's key event.

Users doing heavy data entry like being able to push that Enter-Key and move
to the next control without having to click to it.
 
In heavy data entry solutions, I like to use the Enter-Key on a form's
control in the control's key event.

Users doing heavy data entry like being able to push that Enter-Key and move
to the next control without having to click to it.

In heavy data entry solutions, I like to use the Enter-Key on a form's
control in the control's key event.

Users doing heavy data entry like being able to push that Enter-Key and move
to the next control without having to click to it.

As do I (especially for Access migrations), I only included my method
because it seemed that the OP was trying to activate a Save routine
whenever a user pressed enter. If so, it is typical to also have a
save button on the form - so if the OP just wanted the enter key to
run the save routine the button uses, it would be easier to set the
save button as the default button instead of using key hooks (IMO).

Thanks,

Seth Rowe
 
Use this :
Private Sub textbox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyDown

if e.KeyCode = Keys.Return Then

----- Process to Insert value

sendkeys.send("{TAB}")

End sub


Try this
 
Use this :
 Private Sub textbox1_KeyDown(ByVal sender As Object, ByVal e As System..Windows.Forms.KeyEventArgs) Handles textbox1.KeyDown

if e.KeyCode = Keys.Return Then

----- Process to Insert value

sendkeys.send("{TAB}")

End sub

Try this

I've use the following so that users can use either the enter or the
tab key to move to the next control. Just make sure that your controls
are properly ordered via the tabindex property.

' GOT THIS FROM THE NET. NOT SURE WHERE.
<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall,
_
CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", _
ExactSpelling:=True, SetLastError:=True)> _
Public Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Integer, ByVal
dwExtraInfo As Integer)
End Sub

Public Sub FakeTab()
keybd_event(9, 143, 0, 0) '; // Tab Press
End Sub

Your form's KeyPreview property should be set to True, Then in your
form's keydown event:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
FakeTab()
End If
End Sub

hth
 
Back
Top