none
Visual Basic 2008 Express: Enter Key Beeping RRS feed

  • Question

  • I've been programming in various languages for quite some time now. I've spent most of the last ten years working with VBA to create custom Access applications. So I'm quite frustrated that I can't figure out my current problem.

    I recently installed and started working with VB2008Express. My exact problem is that whenever the enter key is pressed within a text box control, the computer beeps (not the actual PC speaker, the default windows "donk" sound). I've tried to cancel the keystroke with the e.handled method that I found after much searching, but that doesn't stop the beep.

    I really would prefer to not have a sound every time the enter key is used. The program at hand is a Math Flash Card program I wrote for my kids and it starts to drive me a little nuts after a while to hear, "donk, donk, donk, etc."

    Intercepting and canceling keystrokes in VBA is no big deal, but it seems to be a gargantuan task in VBE.

    Any suggestions?
    Tuesday, September 30, 2008 4:23 AM

Answers

  • This is a pretty common issue. You do need to handle the keypress:

        Private Sub TextBox1_KeyDown(ByVal sender As Object, _ 
           ByVal e As System.Windows.Forms.KeyEventArgs) _ 
           Handles TextBox1.KeyDown 
            If e.KeyCode = Keys.Enter Then 
                e.SuppressKeyPress = True 
            End If 
        End Sub 


    Stephen J Whiteley
    Tuesday, September 30, 2008 11:13 AM
    Moderator

All replies

  • Hello kugaknk and welcome to Visual Basic World,
             Your problem sounds in your hardware as neither of any version of VB.NET (and I may claim that older versions of VB) textbox control came with that sound. Personally I work now on VS 2008. You may send me the project to check it out. 

    Waleed El-Badry Teaching Assistant Faculty of Engineering Misr University for Science & Technology
    Tuesday, September 30, 2008 8:42 AM
  • This is a pretty common issue. You do need to handle the keypress:

        Private Sub TextBox1_KeyDown(ByVal sender As Object, _ 
           ByVal e As System.Windows.Forms.KeyEventArgs) _ 
           Handles TextBox1.KeyDown 
            If e.KeyCode = Keys.Enter Then 
                e.SuppressKeyPress = True 
            End If 
        End Sub 


    Stephen J Whiteley
    Tuesday, September 30, 2008 11:13 AM
    Moderator
  • This works for me:

    Private Sub QuickSearchHook(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                Handles txtQuickContractSearch.KeyPress

            ' Check keypress.
            If e.KeyChar = ChrW(Keys.Enter) Then
               ' Supress beep sound due to hitting enter in a single line text box.
                e.Handled = True
                Exit Sub
            End If

        End Sub
    • Proposed as answer by Jake Fosheezee Thursday, February 4, 2010 9:04 PM
    Thursday, February 4, 2010 9:02 PM
  • This is a pretty common issue. You do need to handle the keypress:

        Private Sub TextBox1_KeyDown(ByVal sender As Object, _ 
           ByVal e As System.Windows.Forms.KeyEventArgs) _ 
           Handles TextBox1.KeyDown 
            If e.KeyCode = Keys.Enter Then 
                e.SuppressKeyPress = True 
            End If 
        End Sub 


    Stephen J Whiteley

    Perfect answer.
    Saturday, February 6, 2010 3:06 AM