Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using enter button to give next control focus

Status
Not open for further replies.

stx

Programmer
Sep 24, 2002
62
BE
i am using the following code the give the next control on the form the focus when the enterkey is pressed. The good thing is that it works, the bad thing about it is that it produces an annoying sound every time the enter button is pressed.

Private Sub frmKlantInfo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If Asc(e.KeyChar) = 13 Then
SendKeys.Send("{TAB}")
End If
End Sub

In vb6 you can resolve this by setting keyascii = 0. Is there a solution in .NET?

thnx for the help
 
Try adding e.handled = true. This should tell Windows not to try and process the keystroke, but that your code has handled instead.
 
benvegiard,

i put in your suggestion but it still kicks out a ding. below is the code for the keypress event

Private Sub txtUserName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUserName.KeyDown
'if they pressed the enter key go to the password field
If e.KeyCode.Equals(Keys.Enter) Then
Me.txtPassword.Focus()
End If
End Sub

any other ideas would be great.
Bueller
 
Come to think of it, I had this same problem when I was making Control-A do "select all" in a text box. I also tried doing e.Handled = True but it still beeped. :-(
 

instead of"
SendKeys.Send("{TAB}")

try
SelectNextControl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top