Click here to Skip to main content
14,605,760 members
Rate this:
Please Sign up or sign in to vote.
See more:
Ok at wits end (though it was a short trip)
I have a textbox on a popup menu, when I enter text, then press the enter key I get a ding. Researched the cr@p out of it and nothing works.

The code is essentially...
Private Sub ToolStripTextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ToolStripTextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            e.Handled = True 
            e.SuppressKeyPress = True
        End If
    End Sub

What I have tried:

I've used both the e.Handled = True and e.SuppressKeyPress = True alone and in combination/order and nothing seems to stop the ding!
Updated 9-Apr-16 7:26am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Did you have any other button in the control? One solution comes if you select that "other" button or control when you press enter.

It happens when the textbox.multiline=false and there's no other control to select.

Take a look here:[^]

Hope this helps!
bayotle 11-Apr-16 7:10am
Thanks but that's related to vb6, no way I can see to set Keycode = 0
Ivan_FM 11-Apr-16 7:24am
Ok, try this again. I've just tried it right now and Works fine.

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
Select Case e.KeyCode
Case Keys.Enter
e.SuppressKeyPress = True
End Select
End Sub

Because the textbox has multiline=false, you can supress this key and there's no problem. Also you can convert the "Enter" kepress to a "TAB" adding it to the case if you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100