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
-
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
-
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 ClassHow do I check for enter?
-
Got it from:
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 SubHardCode : You should clean that up to only have this after the If statement: Process.Start("https://www.example.com/search.php?search=" & SearchBox.Text.Trim) Much cleaner. You may also want to validate that something was entered in the TextBox.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.