| | |
need help with a custom web browser
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
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!
Any help would be appreciated, thanks in advance!
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
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.
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!!!
C# Syntax (Toggle Plain Text)
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)); 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!!!
![]() |
Similar Threads
- Hiring Designer - Web 2.0 style (Web Development Job Offers)
- Help Web Browser Open File Dialog Problems (VB.NET)
- Looking for web developers in Delaware (Web Development Job Offers)
- Web browser (IT Professionals' Lounge)
- Creating a web browser, where to start? (IT Professionals' Lounge)
- Lead Web Developer- London - £45k (Web Development Job Offers)
- Need Web Designer for Project (Web Development Job Offers)
- Can't Change Default browser (Web Browsers)
- Custom Web Server Control That Validate Itself (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: how to create shortcuts?
- Next Thread: C# console applications & highlighting output to screen
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view webbrowser windows winforms wpf xml






