3

我有一个 ToolStripTextBox(它的名称是 SearchBox),当用户键入某些内容并按 Enter 后,我希望它会将它们带到一个 URL。我已经整理好了 URL 部分,但我需要知道之后会发生什么

Handles SearchBox.{what?}

当用户按下“输入”时,我在智能感知弹出窗口中看不到任何事件。

所以,换句话说,我如何在用户按下回车后执行一个动作?

    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
4

3 回答 3

2

得到它:

在文本框的 keyup 事件中按下回车键后消除回车键

不准确,但有帮助。

    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
于 2009-02-22T18:14:35.417 回答
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

于 2009-02-22T17:52:46.827 回答
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

如何检查输入

于 2009-02-22T18:08:05.370 回答