bjwade62 Posted September 22, 2006 Posted September 22, 2006 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 Quote
headkaze Posted September 22, 2006 Posted September 22, 2006 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: 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. Quote
bjwade62 Posted September 22, 2006 Author Posted September 22, 2006 Thanks for the reply but I'm getting the blue squigle line under the First ( of String.Join('+', myTextBox.Text.Split(' ')); Says, expression expected. 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: 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. Quote
bjwade62 Posted September 22, 2006 Author Posted September 22, 2006 Got it. WebBrowser1.Navigate("http://www.google.com.au/search?q=" + txtWebSearch.Text) Thanks for helping. 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: 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. Quote
headkaze Posted September 22, 2006 Posted September 22, 2006 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. 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. Quote
bjwade62 Posted September 22, 2006 Author Posted September 22, 2006 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. 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. 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.