StrataFrame Forum

How to make a control Tab to the next control when pressing Enter key?

http://forum.strataframe.net/Topic16119.aspx

By Edhy Rijo - 5/4/2008

Hi All,

I am creating a VB version of the Currency Control created by Rogerio Mauri here http://forum.strataframe.net/Topic14533-26-1.aspx

Basically I have a whole bunch of currency fields and need a simple solution to all of them. I would like that when the user press the Enter key if will simply go to the next control like the Tab key does.  I found the following code in the Internet:

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

     'Tab to the Next Control when presing Enter

     If e.KeyCode = Keys.Return Then

          SendKeys.Send("{TAB}")

     End If

End Sub

It is working fine, but obviously this will fire for every key pressed in the control, is this the correct event to handle that feature, or is there another way to get this done?

P.S.

I will post the final version of this class when done.

By Trent L. Taylor - 5/5/2008

You will want to look at the SelectNextControl method of a control or a form.  It selects the next control based on the tab order.

For example:

MyTextBox.SelectNextControl()