开发者

How do I open a Google-search in Firefox when I click on a label?

I have a label that displays graphics card name, make and some other information, and I'm working on making it so that when its clicked, it opens Firefox and searches Google for the name of the card.

I tried using "let met Google that for you" but it searches for each work individually.

This is what I've tried so far and it kind of works but there's something wrong with it:

private void label13_Click(object sender, EventArgs e)
{
    ManagementObjectSearcher Vquery = new ManagementObjectSearcher(
        "SELECT * FROM Win32_VideoController");
    ManagementObjectCollection Vcoll = Vquery.Get();
    foreach (ManagementObject mo in Vcoll)
    {
        System.Diagnostics.Process CcleanerA = System.Diagnostics.Process
            .Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe",
                "http://google.com/?q="+(mo["name"].ToString()));
    }
}

ok well i got it to search the right thing, but it searches it twice, in 2 tabs so whats wrong?

             private void Vcard_Click(object sender, EventArgs e)
     {
         ManagementObjectSearcher Vquery = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
         ManagementObjectCo开发者_如何学JAVAllection Vcoll = Vquery.Get();
         foreach (ManagementObject mo in Vcoll)
         {
             System.Diagnostics.Process.Start("http://www.google.ca/search?hl=en&q=" + mo["name"].ToString());
         }
     }


Process.Start(...) Is probably your best friend in this case. You can use it to launch Firefox. FF should open a new tab if it's already open.

The first parameter after the FF Executable is the url to browse to.

However You should probably just launch the URL, this'll open the default browser.

System.Diagnostics.Process.Start("http://www.microsoft.com");

Edit

You know, Google has a search API exposed to the world, you could just use the API to search for the products and then present the list of results right inside your program! Then you aren't relying on the browser.

Also

There's a WebBrowser control in .NET that you can just navigate people to the google GET Url:

http://www.google.ca/search?hl=en&q=nvidia+7900


This is basic Google search techniques 101 - you have what is known as a phrase (i.e. a name made up of multiple words), so you need to surround them with quotes before executing the search.

You should also consider converting the search terms to lower case, if there are any capital letters in the phrase then Google will make the search case sensitive, which may cut down your result set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜