加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

e.Handled在VB.net 2010中无效

发布时间:2020-12-17 07:18:36 所属栏目:百科 来源:网络整理
导读:我在vb.net上做了一个快速的网络浏览器,我有它,所以当你按Enter键导航到textbox1中的网页.唯一的问题就是每次按下回车都会发出哔哔声.我尝试使用e.Handled = True,但它没有做任何事情.这是我的按键代码 Private Sub TextBox1_KeyDown(ByVal sender As Object
我在vb.net上做了一个快速的网络浏览器,我有它,所以当你按Enter键导航到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.

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读