Solved

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

Posted on 2007-11-30
9
491 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
 

Author Comment

by:Jimmy Lea
ID: 20390387
Sorry Idle_Mind don't know where I got Bob from.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now