Using Enter key to Tab between fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Having taken the plunge to
update from VB4 to Visual Basic.NET, I'm having trouble with some syntax.
Specifically, I used to use the Keypress event to send a Tab when the Enter
key was pressed:
Private Sub txthead1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then SendKeys "{TAB}"
End Sub

I would like to do this in Visual Basic.NET but can't for the life of me
work out how to do this! Any advice would be very gratefully received.

I'm also having a problem getting a text box to hightlight its contents when
it gets the focus - in VB4 is used to use:
Private Sub txthead1_GotFocus()
txthead1.SelStart = 0
txthead1.SelLength = Trim(Len(txthead1.Text))
End Sub

However it seems that this too has changed (and the VB6 converter tool isn't
a lot of help to me, as I can't yet understand what half of its suggestions
mean!).

Many thanks in advance for any advice.
 
Hi

Try these.

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

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
System.Windows.Forms.SendKeys.Send("{TAB}")

End Sub


Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus

TextBox1.SelectAll()

End Sub

Mike
 
Many thanks Michael: I shall try your code suggestions in the morning (when
my eyes have uncrossed from today's headbanging!) ;-)
 

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

Back
Top