我目前正在用VB.net构建一个web浏览器,我很难让e.SuppressKeyPress = True正常工作。我在我的地址栏上使用了这段代码,这样用户就可以点击enter并导航到所需的页面。我的整个代码:
Private Sub AddressBar_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles AddressBar.KeyUp
On Error Resume Next
If e.KeyCode = 13 Then
Dim textArray = AddressBar.Text.Split(" ")
If (AddressBar.Text.Contains(".") = True And AddressBar.Text.Contains(" ") = False And AddressBar.Text.Contains(" .") = False And AddressBar.Text.Contains(". ") = False) Or textArray(0).Contains(":/") = True Or textArray(0).Contains(":\") Then
Navigate(AddressBar.Text)
Else
Navigate("http://www.google.com/search?q=" + AddressBar.Text)
End If
WebControl.Focus()
e.SuppressKeyPress = True
End If
End Sub我尝试将e.SuppressKeyPress = True移动到多个不同的位置,但都不起作用。有什么建议吗?
发布于 2013-10-25 00:35:09
不能在KEYUP事件中隐藏该密钥,该密钥已被处理。微软甚至给你提供了这个选项,这是相当愚蠢的。在示例应用程序中尝试此代码并比较结果
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.A Then
e.SuppressKeyPress = True
End If
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "b" Then
e.Handled = True
End If
End Sub
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.C Then
e.SuppressKeyPress = True
End If
End Subhttps://stackoverflow.com/questions/19571050
复制相似问题