Tag Archives: disable beep on enter

Disable that Beep while pressing the “Enter/Return” key in a Textbox using VB6

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)
 

This works with Visual Basic 6.0 and VB 5.0.

'VB 5.0/6.0

'Copy and Paste this code in your Textbox_KeyPress() event.

    If KeyAscii = 13 Then  

        KeyAscii = 0   

    End If

Disable ‘Beep’ in Textbox when pressing the ‘Enter’ Key – VB.NET 2008/2010, VB 2013

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)
 

This will stop that beep from sounding when you press the Enter key in the textbox or combobox control. This works for VB 2005, VB 2008, Visual Basic 2010, and VB 2013.

Just put the code in the Textbox _KeyDown event.

        '
        'This code will disable the ‘Beeping’ you get when you press the ‘Enter’ key in a
        'Textbox control. This code needs to go into the Textbox_KeyDown’ event.
        '
        If e.KeyCode = Keys.Enter Then

            e.SuppressKeyPress = True

        End If

 

Why it Beeps Pressing Enter in a Textbox Control and How to Fix it in .NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

I’ve seen many questions on how to disable the beep that occurs when you press the ‘Enter’ key in a single line Textbox control or a Combobox control. From my understanding the reason is because in Single Line mode, the textbox control doesn’t know how to handle the Enter/Return key, and is basically reporting an error when you get the beep. But it is pretty simple to keep that from happening.

Visual Basic 2005, VB 2008, and VB 2010

        ' This code will disable the 'Beeping' you get when you press the 'Enter' key in a Textbox
        'control. This code needs to go into the 'Textbox_KeyDown' event.
        If e.KeyCode = Keys.Enter Then

            e.SuppressKeyPress = True

        End If

Visual Basic.NET 2002/2003

The code below will also work with VB 05, 2008, and Visual Basic 2010. But the above snippet will NOT work on Visual Basic.NET 2002 or .NET 2003.

        '
        'This is for VB.NET 2002, .NET 2003, and Higher
        'Put in your textbox controls Textbox_KeyPress
        '
        If e.KeyChar = Chr(13) Then

            e.Handled = True

        End If
        '
        'Or you can use the code below. Which will be the same result as above.
        '
        If e.KeyChar = vbCr Then

            e.Handled = True

        End If

That should take care of the beeping problem. Take care.