Solved

How do I get rid of the beep when you press Enter?

Posted on 2007-11-30
9
495 Views
Last Modified: 2008-02-01
I want to use the Enter key like a Tab key.  I have code to do that, but it still beeps every time you press Enter.  How do I get rid of that? In VB 2005
Private Sub TxtSeasonal_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtSeasonal.KeyDown
        If e.KeyCode = 13 Then
            SendKeys.Send("{tab}")
        End If
    End Sub

Open in new window

0
Comment
Question by:Jimmy Lea
  • 4
  • 4
9 Comments
 
LVL 19

Expert Comment

by:darron_chapman
ID: 20387060
Try this....
Private Sub TxtSeasonal_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtSeasonal.KeyDown
        If e.KeyCode = 13 Then
            SendKeys.Send("{tab}")
            e.KeyCode = 0
        End If
    End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 20387301
darron...that looks like a VB6 approach forced into .Net syntax...

VB6 would look like:

    Private Sub TxtSeasonal_KeyPress(KeyAscii As Integer)
        KeyAscii = 0
        SendKeys "{Tab}"
    End Sub

In VB.Net, though, it would be:

    Private Sub TxtSeasonal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtSeasonal.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            e.Handled = True
            SendKeys.Send("{tab}")
        End If
    End Sub
0
 

Author Comment

by:Jimmy Lea
ID: 20390384
Thanks for the reply guys.

Darron,
e.KeyCode = 0
gives err saying it is read only
'Property KeyCode is Read Only'

Bob,
e.Handled = True in the KeyDown
nothing changed
I also tried it as a KeyPress event and e.Handle = True
When I did that it would not except the text.  But it didn't beep.

Is there something I'm doing wrong?
Any other thoughts?

Thanks
Jim



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jimmy Lea
ID: 20390387
Sorry Idle_Mind don't know where I got Bob from.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 20391428
It worked fine for me in the KeyPress() event...

Show us what code you are CURRENTLY using.
0
 

Author Comment

by:Jimmy Lea
ID: 20393670
The code snipplet in the original post is what I am Currently using.  What are you asking for?  
This is a data entry app that takes numbers, I wanted the users to be able use the number pad.  So I would like them to be able to use the Enter key to go between txt boxes.  Is there a property in the txt box that makes the keypress event work?  I'm fairly green at programming so it may be something simple.  Do you want the code for the whole form?

Thanks for your reply
Jim
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 20393688
It should work with just the KeyPress() event:

    Private Sub TxtSeasonal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtSeasonal.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            e.Handled = True
            SendKeys.Send("{tab}")
        End If
    End Sub

GET RID OF THE KEYDOWN() CODE YOU ALREADY HAVE...
0
 

Author Comment

by:Jimmy Lea
ID: 20393715
Ok, when I tried the the Keypress event I still had the Keydown in there.  I'm sure that was it. I will replace it Monday and give it a go.  I figured it was something silly.  Thanks for your help.

Jim
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 20393737
No problem.  Let us know if it still doesn't work as expected...we'll figure it out!  ;)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question