我有一个ToolStripTextBox(它的名字是SearchBox),我想在用户输入内容并按下输入后将它们带到URL。我已经整理了URL部分,但我需要知道
之后的内容Handles SearchBox.{what?}
当用户按下“输入”时,我在intellisense弹出窗口中看不到任何事件。
因此,换句话说,如何在用户按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
答案 0 :(得分:2)
来自:
eliminate the enter key after pressing it in the keyup event of a textbox
不确切,但有帮助。
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
答案 1 :(得分:1)
您可以处理SearchBox_KeyUp或SearchBox_KeyPress事件。
看看这里:
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
答案 2 :(得分:0)
这是我的代码,按任意键会导致URL加载!
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
如何查看输入?