Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 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...
VB
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
            Process(ToolStripTextBox1.Text)
        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!
Posted
Updated 9-Apr-16 7:26am

1 solution

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: https://support.microsoft.com/en-us/kb/140882[^]

Hope this helps!
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900