C# 让我的搜索框工作吗?

C# 让我的搜索框工作吗?,c#,windows-phone-7,C#,Windows Phone 7,我正在创建一个web浏览器,它有一个搜索框和go按钮。你能帮我设置一下吗?是否也有一种方法可以使用您在网站上使用的html代码搜索栏 这是我的代码: private void button4_Click(object sender, RoutedEventArgs e) { string site; site = textBox1.Text; webBrowser1.Navigate( new Uri(

我正在创建一个web浏览器,它有一个搜索框和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));

根据你的评论,它会转到bing,不会搜索任何内容

要解决这个问题,您需要填充querystring参数“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));

这两种方法中的任何一种都适用于您,我个人的偏好是第二种。

您是否尝试过在bing url中添加textBox1.Text?您目前正在使用bing吗?bing没有搜索的唯一问题是什么?我正在尝试编程文本框1中的文本,以便在按下go时搜索bing。我理解这一点。当前,当您按下按钮时,是否发生任何事情?你看到bing的主页了吗?如果是这样的话,这是一个很容易的改变,如果不是的话,我帮不了你的忙。点击bing搜索,什么也不搜索