Solved

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

Posted on 2007-11-30
9
497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

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

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 86

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 86

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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