Hello, I'm trying to make a custom web browser. I'm using the webBrowser control that does a huge part of the job for me. I wanted to add a search option to it (when you click search the browser sends you to lets say google and shows you the results). What I can't figure out is how to send the string that the user is looking for to google.com and to have it display the results.
Any help would be appreciated, thanks in advance!

Well if you've worked out how to read a page, posting to a page shouldnt be that much harder. have you tried posting the variable to the search page?

you weren't to specific, but i am going to assume you are going for the internet explorer7+ and firefox style search box where the search box is a separate text box, this code would imply that you have a webbrowser control called "webbrowser1" and a textbox for the search called "searchTxt" and this code would be in a click event method for a search button.

string breaker = " ";
         char[] delimiter = breaker.ToCharArray();
         string[] splitterArray = searchTxt.Text.Trim().Split(delimiter);
         string queries = "";

         foreach (string s in splitterArray)
             queries += s + "+";

         //remove extra plus at the end of queries
         queries.Substring(0, (queries.Length - 1));


first we create a delimiter to separate the search terms for use on google, this would also work for yahoo, and wikipedia, and many others you just have to check where to put the queries and get the search url from their site this is set up ready to work on google

then we take the string from the search text box and separate it by spaces into an array, after that we loop through the array and add all the search words together into one string adding a + between each one because this is the format that google and yahoo both use.

then we use substring to remove a + that is added at the end that is unnecessary, this could have been avoided, but this is a simple and effective solution, so we will go with that.

finally we take the url of google's search page with its query string ready to accept our values, and we simply add to it our search queries variable and put it in the Navigate function of the webbrowser control.

and we have our search results!

this is just one way, be creating, be inspired, just be anything but satisfied. This will get you started. but if you want to have happy users you will need to give options to choose which search engine they want to use, or even add their own search engines!

Happy Coding!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.