vb.net - e.Handled 在 VB.net 2010 中不起作用

标签 vb.net visual-studio-2010 beep

我在 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/

相关文章:

vb.net - 使用LINQ过滤DBNull

c - 在 C、MacOS 中播放提示音

c# - Bool 属性在未被调用的情况下设置为 true

c# - 通过 VS 接口(interface)进行表单控制的多个事件处理程序

c++ - 传递额外的 wParam/lParam 参数?

python - 减少python winsound中的 “raindrop”声音

Java Swing : Audible sound when altering hidden UI element on unselected panel of JTabbedPane

vb.net - VB.NET 中的运算符重载

vb.net - 如何在 Vb net 中旋转标签?

c# - 为什么我们有这么多种程序集加载方法?