Use "Enter" to "Tab"

D

Doug Bell

Hi,
I have just built a small application with a form that has one Text Box and
one Check Box and a couple of Command Buttons.

What I am trying to achieve is that if the Text Box has focus and the User
hits the "Enter" button the focus will move to the next Tab item (i.e. the
Check Box). Likewise on the Check Box but obviously if a Command Button has
the focus, it will initiate the Click event

I have set the Forms CancelButton to the button that closes the form and I
have its AcceptButton set to none.

Do I have to trap every keystroke and test for "Enter"? Or is there a
property that I am missing?

Thanks

Doug
 
K

Ken Tucker [MVP]

Hi,


Set the forms keypreview property to true.

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

If e.KeyCode = Keys.Enter Then

Me.SelectNextControl(Me.ActiveControl, True, True, True, True)

End If

End Sub



Ken

-----------------


Hi,
I have just built a small application with a form that has one Text Box and
one Check Box and a couple of Command Buttons.

What I am trying to achieve is that if the Text Box has focus and the User
hits the "Enter" button the focus will move to the next Tab item (i.e. the
Check Box). Likewise on the Check Box but obviously if a Command Button has
the focus, it will initiate the Click event

I have set the Forms CancelButton to the button that closes the form and I
have its AcceptButton set to none.

Do I have to trap every keystroke and test for "Enter"? Or is there a
property that I am missing?

Thanks

Doug
 
D

Doug Bell

Hi Ken,
Thanks
That does cause the "Enter" Key to tab but when it is pressed there is an
audible Ding! from the PC similar to an Error Warning Ding!

Doug
 
C

Cor Ligthert

Doug,

I thought this is once provided by Armin Zingler,
\\\
Private Sub TextBox1_KeyPress( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress
If e.KeyChar = vbCr Then
e.Handled = True
End If
End Sub
///

I hope thie helps?
Cor
 
D

Doug Bell

Thanks Cor,

I added "
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)"

and it is working well.

If e.KeyChar = vbCr Then

e.Handled = True

Me.SelectNextControl(Me.ActiveControl, True, True, True, True)

End If

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top