Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / March 2007



Tip: Looking for answers? Try searching our database.

Enter key to act like Tab key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
libbeyc@schoollink.net - 30 Mar 2007 15:33 GMT
I have a form with a large number of (input) text boxes.  The input data is all
numerical.  After entering a data point, I would like to be able to press the
*Enter* key and have the focus move to the next tab position.

From the help files:
Sub Text1_KeyPress (KeyAscii as integer)
  Mychar = Chr(KeyAscii)
 'Perform an operation using Mychar
End Sub

Is there a way for the sub to read the Enter key as Chr(13) and then perform a
Tab operation like Chr(9)?

'Perform an operation using Mychar
If Mychar = 13 then VbTab
 or simply
If Mychar = 13 then  Chr(9) ?
Is Chr(9) an "operation" ?

Do I need a separate sub for each text box?

Chuck
--
Michel Vanderbeke - 30 Mar 2007 15:57 GMT
>I have a form with a large number of (input) text boxes.  The input data is
>all
[quoted text clipped - 21 lines]
>
> Chuck

Just insert this code on the KeyDown and KeyPress events of the form:

Private Sub frmForm_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

  Select Case e.KeyCode
   Case Keys.Enter
    Me.SelectNextControl(CType(Me.ActiveControl, TextBox), True, True,
True, False)
  End Select

End Sub

Private Sub frmForm_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

   '==================
  'prevents beep on ENTER
  '==================
  If e.KeyChar = Chr(13) Then
   e.Handled = True
  End If

End Sub

and do not forget to set the KeyPreview property of the Form to True.

Many greetings from Brugge (Bruges - Belgium),

Michel
libbeyc@schoollink.net - 30 Mar 2007 20:05 GMT
Michel,
Thank you for your help.

>>I have a form with a large number of (input) text boxes.  The input data is
>>all
[quoted text clipped - 26 lines]
>Private Sub frmForm_KeyDown(ByVal sender As Object, ByVal e As
>System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Error "End of statement expected" at "Handles"
*Handles Me.KeyDown*  placed on separate line was accepted,  but probably not
correct.  Could not run because of error in Select Case

>   Select Case e.KeyCode
>    Case Keys.Enter
>     Me.SelectNextControl(CType(Me.ActiveControl, TextBox), True, True,
>True, False)
"=" expected at end of statement??

>   End Select
>
> End Sub
>
> Private Sub frmForm_KeyPress(ByVal sender As Object, ByVal e As
>System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Again *Handles Me.KeyPress*  had to be placed on separate line.

>    '==================
>   'prevents beep on ENTER
[quoted text clipped - 10 lines]
>
>Michel
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.