问题
I need to stop the "ding" sound while pressing enter but I use it to send a message. There is my code:
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
I'm using an another sound to notify when a textbox changed but this textbox2 is for sending messages and when it sends it using enter this "ding" plays and the other sound together.
回答1:
Try setting e.Handled and e.SuppressKeyPress to 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
This should suppress the "ding".
来源:https://stackoverflow.com/questions/30529193/how-can-to-stop-the-ding-sound-while-pressing-enter