views:

757

answers:

3

I have a ToolStripTextBox (the name of it is SearchBox) and I would like it when after the user types something and presses enter it takes them to a URL. I've got the URL part sorted out, but I need to know what goes after

Handles SearchBox.{what?}

I don't see any event in the intellisense popup for something when the user presses "enter."

So, in other words, how do I perform an action after the user presses enter?

    Private Sub ToolStripComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBox.**?????**

    Dim SearchString As String
    SearchString = SearchBox.Text

    Dim URL As String
    URL = ("https://www.example.com/search.php?&q=" + SearchString)

    Process.Start(URL)
End Sub
+1  A: 

You can handle the SearchBox_KeyUp or the SearchBox_KeyPress event.

Take a look here:

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.keyup.aspx

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.keypress.aspx

Tommy Hui
Thanks. I can't figure out how to implement it though. Will try.
A: 

This is my code, pressing any key causes the URL to load!

    Public Sub SearchBox_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles SearchBox.KeyPress

        Dim messageBoxVB As New System.Text.StringBuilder()
        messageBoxVB.AppendFormat("{0} = {1}", "Enter", e.KeyChar)
        messageBoxVB.AppendLine()


        Dim SearchString As String
        SearchString = SearchBox.Text

        Dim URL As String
        URL = ("https://www.example.com/search.php?search=" + SearchString)

        Process.Start(URL)
    End Sub
End Class

How do I check for enter?

+2  A: 

Got it from:

http://stackoverflow.com/questions/236675/eliminate-the-enter-key-after-pressing-it-in-the-keyup-event-of-a-textbox

Not exact, but it helped.

    Public Sub SearchBox_KeyPress(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SearchBox.KeyDown

    If e.KeyCode = Keys.Enter Then

        Dim SearchString As String
        SearchString = SearchBox.Text

        Dim URL As String
        URL = ("https://www.example.com/search.php?search=" + SearchString)

        Process.Start(URL)

    End If
End Sub
HardCode