如何在按下Enter键时停止“叮”声

时间:2015-05-29 12:05:53

标签: vb.net

我需要在按Enter键时停止“叮”声,但我用它来发送信息。有我的代码:

    Private Sub textbox2_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
 Handles TextBox2.KeyDown
    If e.KeyCode = Keys.Enter Then
        TextBox3.ReadOnly = True
        If TextBox2.Text = ("") Then
        Else
            Dim PostData = "token=" & TextBox1.Text & "&msg=" & TextBox3.Text & ": " & TextBox2.Text
            Dim request As WebRequest = WebRequest.Create("http://url.com/msg.php")

            request.Method = "POST"
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(PostData)
            request.ContentType = "application/x-www-form-urlencoded"
            request.ContentLength = byteArray.Length
            Dim dataStream As Stream = request.GetRequestStream()
            dataStream.Write(byteArray, 0, byteArray.Length)
            dataStream.Close()
            Dim response As WebResponse = request.GetResponse()
            dataStream = response.GetResponseStream()
            Dim reader As New StreamReader(dataStream)
            Dim responseFromServer As String = reader.ReadToEnd()
            reader.Close()
            dataStream.Close()
            response.Close()
            TextBox2.Clear()
        End If
    End If
End Sub

当文本框发生变化时,我正在使用另一种声音进行通知,但此文本框2用于发送消息,当它使用输入时,输入此“ding”播放,另一种声音一起播放。

1 个答案:

答案 0 :(得分:1)

尝试将e.Handlede.SuppressKeyPress设为True

Private Sub TextBox2_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyDown
    If e.KeyCode = Keys.Enter Then
        ' Your code...

        e.Handled = True
        e.SuppressKeyPress = True
    End If
End Sub

这应该压制“叮”。