Visual studio nicely provides built-in auto-complete functionality for text boxes and combo boxes. I am using the suggest method of auto complete that provides the user with a list of choices filteres by what they have type. The problem I am having is that when the user makes a selection (via the mouse) VS places the selected text into the textbox and also simulates the enter key being pressed on the textbox.
In my program the enter keyup event is used to send the text entered in the text box to the a COM port. In order for this to work as desired the user must be able to select an auto-complete option and then add to it so that they can change settings.
Is it possible to stop it from triggering that event or to intercept it? I am unsure if it is possible or how to determine the origin of a keypress.
Here is the code for the KeyUp even as well as for the KeyPress Event:
Private Sub txtInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress
If e.KeyChar = Chr(13) Then
e.Handled = True
End If
End Sub
Private Sub txtInput_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtInput.KeyUp
If e.KeyValue = Keys.Enter Then
If txtInput.Text.ToLower = "cls" Or txtInput.Text.ToLower = "clr" Or txtInput.Text.ToLower = "clear" Then
txtOutput.Text = ""
Else
If SerialPort1.IsOpen Then
SerialPort1.Write(txtInput.Text)
Else
MsgBox("The serial port is not open")
End If
End If
txtInput.Text = ""
e.Handled = True
e.SuppressKeyPress = True
End If
End Sub
The auto-complete functionality was accomplished through the properties of the control, the only code for that was to generate the auto-complete list.
Thanks in advance for any help.
P.S. I am using VB.net, but if necessary I can figure out how to get it from another .net language to VB