让我的搜索框工作?

时间:2012-12-20 02:02:39

标签: c# windows-phone-7

我正在创建一个网络浏览器,它有一个搜索框和go按钮。你能帮帮我解决这个问题吗?是否还有一种方法可以使用您在网站上使用的html代码搜索栏?

这是我的代码:

     private void button4_Click(object sender, RoutedEventArgs e)
     {
        string site;
        site = textBox1.Text;
        webBrowser1.Navigate(
             new Uri("http://m.bing.com/search?q=", UriKind.Absolute));

1 个答案:

答案 0 :(得分:1)

根据你的意见,它会转向bing并且不进行任何搜索。

要解决此问题,您需要填充查询字符串参数“q”。这真的很简单:

private void button4_Click(object sender, RoutedEventArgs e)
{
    string site;
    site = textBox1.Text;
    webBrowser1.Navigate(
         new Uri("http://m.bing.com/search?q=" + site, UriKind.Absolute));

您还可以使用String.Format函数获取:

private void button4_Click(object sender, RoutedEventArgs e)
{
    string site;
    site = textBox1.Text;
    webBrowser1.Navigate(
         new Uri(System.String.Format("http://m.bing.com/search?q={0}", site), UriKind.Absolute));

这些都适合你,我个人的偏好是第二个。