How to set focus to controls when i press enter key in VB.NET

  • Thread starter Thread starter Mamatha
  • Start date Start date
M

Mamatha

Hi

I have a samll application.
In that i have one textbox and one button.
When i enter some text in text box and press enter then
the button will have a focus.
How can i do this?

Mamatha
 
Try this:

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
Me.Button1.Focus()
End If
End Sub
or:

Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Enter Then
Me.Button1.Focus()
End If
End Sub


spigi
Hello Mamatha,
 

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