我在 vb.net 中做了一个快速的网络浏览器,我有它,所以当你按下回车键时,它会导航到 textbox1 中的网页。唯一的问题是每次按回车键都会发出哔哔声。我尝试使用 e.Handled = True,但它没有做任何事情。这是我的按键代码
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.Handled = True
WebBrowser1.Navigate(TextBox1.Text)
End If
End Sub
我以为 e.Handled 会让烦人的哔哔声消失,但事实并非如此。
最佳答案
KeyEventArgs
您想要的属性不是 Handled但是 SuppressKeyPress .
IE。
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
WebBrowser1.Navigate(TextBox1.Text)
End If
End Sub
从第一个 MSDN 链接:
Handled is implemented differently by different controls within Windows Forms. For controls like TextBox which subclass native Win32 controls, it is interpreted to mean that the key message should not be passed to the underlying native control. If you set Handled to true on a TextBox, that control will not pass the key press events to the underlying Win32 text box control, but it will still display the characters that the user typed.
If you want to prevent the current control from receiving a key press, use the SuppressKeyPress property.
关于vb.net - e.Handled 在 VB.net 2010 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443623/