שתף באמצעות


How to prevent key sound after pressing Enter

Question

Sunday, March 15, 2015 9:21 PM

I don't want to hear "beep" sound after pressing enter in TextBox object.

Is it possible to prevent this?

 Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            MsgBox("You will hear "beep" after you press it")
        End If
    End Sub

All replies (2)

Sunday, March 15, 2015 9:58 PM ✅Answered

Hi,

 I am guessing this is a single line TextBox.  You can use the KeyDown event to detect the Enter key being pressed and Suppress the Key.  If you are using the Enter Key to do something when it is pressed in the TextBox then put it in here instead of the KeyPress event.

    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

            'Do something here if you need to when Enter is pressed

        End If
    End Sub

If you say it can`t be done then i`ll try it


Sunday, March 15, 2015 10:07 PM

Great thanks now it's ok.