Using the WebBrowser Control

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
I'm using thw WebBrowser control on one of my forms. What I'd like to do is have the it do a we search based on the contents of a textbox control.

Anyone know how?

Thanks,
Bernie
 
If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

Eg. Typing "word1 word2 word3" into Google results in:

Code:
http://www.google.com.au/search?q=word1+word2+word3

If you take this as a reference you can take your TextBox text and create a url for it.

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

Then send myURL to your browser control and it should show google with the words from your TextBox.
 
Thanks for the reply but I'm getting the blue squigle line under the First ( of String.Join('+', myTextBox.Text.Split(' ')); Says, expression expected.


headkaze said:
If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

Eg. Typing "word1 word2 word3" into Google results in:

Code:
http://www.google.com.au/search?q=word1+word2+word3

If you take this as a reference you can take your TextBox text and create a url for it.

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

Then send myURL to your browser control and it should show google with the words from your TextBox.
 
Got it. WebBrowser1.Navigate("http://www.google.com.au/search?q=" + txtWebSearch.Text)

Thanks for helping.

headkaze said:
If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

Eg. Typing "word1 word2 word3" into Google results in:

Code:
http://www.google.com.au/search?q=word1+word2+word3

If you take this as a reference you can take your TextBox text and create a url for it.

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

Then send myURL to your browser control and it should show google with the words from your TextBox.
 
All that hoohaa was just to split up the text in the TextBox into an array of words separated by a space, then bring them back together placing a "+" between them.

C#:
myTextBox.Text = "word1 word2 word3";

MessageBox.Show(String.Join("+", myTextBox.Text.Split(' ')));

Will ouput "word1+word2+word3". The error you got was because I accidently used single quotes for a char in the Join method when it expects double quotes for a string.
 
Thanks again. I've found that with the code I included (in my last email), that it will still work on multiple words as your's does.

headkaze said:
All that hoohaa was just to split up the text in the TextBox into an array of words separated by a space, then bring them back together placing a "+" between them.

C#:
myTextBox.Text = "word1 word2 word3";

MessageBox.Show(String.Join("+", myTextBox.Text.Split(' ')));

Will ouput "word1+word2+word3". The error you got was because I accidently used single quotes for a char in the Join method when it expects double quotes for a string.
 
Back
Top