943,647 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2225
  • C# RSS
Jan 6th, 2009
0

need help with a custom web browser

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scylefice is offline Offline
1 posts
since Jan 2009
Jan 6th, 2009
0

Re: need help with a custom web browser

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?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 10th, 2009
0

Re: need help with a custom web browser

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.

C# Syntax (Toggle Plain Text)
  1. string breaker = " ";
  2. char[] delimiter = breaker.ToCharArray();
  3. string[] splitterArray = searchTxt.Text.Trim().Split(delimiter);
  4. string queries = "";
  5.  
  6. foreach (string s in splitterArray)
  7. {
  8. queries += s + "+";
  9. }
  10.  
  11. //remove extra plus at the end of queries
  12. queries.Substring(0, (queries.Length - 1));
  13.  
  14. webbrowser1.Navigate("http://www.google.com/search?q="+queries);

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!!!
Reputation Points: 442
Solved Threads: 89
Master Poster
Diamonddrake is offline Offline
721 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how to create shortcuts?
Next Thread in C# Forum Timeline: C# console applications & highlighting output to screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC