Set Focus

  • Thread starter Thread starter RedS
  • Start date Start date
R

RedS

Hi I have two texbox A and B. What I want to ask is how
to set if I press enter in textbox A and it set focus to
textbox B.
Thanks
 
In a Windows Forms application, you would be looking for the enter key being
pressed during textbox A's KeyPress event.
 
....And, in a Web Forms application, you would write client-side script
(JavaScript) that looks for the enter key being pressed during textbox A's
onKeyPress event handler.
 
Hellow there, If have try this code dusing keydown event

If e.KeyCode = Keys.Enter then
txtA.Focus()
end if

Its work but when I try to click the textbox A again its
locked. How come this happen?
How to do it in keypress event
Thanks
 
Hi there,
I try the code from the link that you gave, it is work
when there is nothing in textbox A I can move to textbox
B when I press enter and I can also return to textbox A.
But the problem comes when I type something in textbox A
then I press enter and it goes to textbox B but I cant go
back to textbox A. How this thing happen?

Thanks
 
Assuming that you have a txt1 and txt2 textbox on your WinForm, this code
works for me:

Private Sub txt2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txt2.KeyPress
If e.KeyChar = Chr(13) Then
txt1.Focus()
End If
End Sub
 

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