E.Handled does not work in VB.net 2010

I made a quick web browser in vb.net, I have one, so when you press the enter button, it goes to the webpage in text box 1. The only thing is that it beeps every time I press enter . I tried using e.Handled = True, but did nothing. Here is my keypress code

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 

I thought e.Handled would make this annoying beep, but he didn't.

+4
source share
1 answer

The KeyEventArgs property you want is not Handled , but SuppressKeyPress .

i.e.

 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 

From the first MSDN link:

Processed is done differently using various controls in Windows Forms. For controls such as TextBox, which use subclasses for their own Win32 controls, this is interpreted as meaning that the key message should not be passed to the main main control. If you set Handled to true in a TextBox, this control will not send key events to the main Win32 text box control, but it will still display the characters that the user types.

If you want the current control to not receive keystrokes, use the SuppressKeyPress property.

+6
source

Source: https://habr.com/ru/post/1434421/


All Articles