Reputation: 4056
I am attempting to allow a user to type in their search query in a textbox and upon using the enter key the text would be passed to a internet search provider of his or her choice, and the resulting webpage would be the search results as if the user had typed in their search query in the internet search provider themselves.
I have already implemented a webbrowser control which has an initialuri property that brings up a website (say http://www.google.com a homepage of the user's choice) upon application startup, and I have also created a search textbar at the top of my application which takes text input from the user.
Upon clicking the enter key when the textbox has focus and the user has typed in their query, I would like the pass the text input from the textbox to a search provider of the users choice (say bing.com, google.com, yahoo.com, etc which would be set under a settings page elsewhere in the application). The issue I am having is figuring out how to pass this textbox text to a search provider and then rendering the results in my webbrowser control. Is this possible, and if so how may this be implemented. I have searched everywhere but for some reason have not found any code to reference or ideas of how this may be implemented. I am new to wp7 and c# so any links, suggestions, or code help would be greatly appreciated! For quick reference I show some code below
MainPage.xaml
<my:FullWebBrowser Name="TheBrowser" Grid.RowSpan="2" InitialUri="http://www.google.com" Height="800" Margin="0,0,0,-690" />
MainPage.xaml.cs
private void BrowserBar_Click(object sender, KeyEventArgs e)
{
//search whats in the searchbar
//use inputscope enter key to start search!
if (e.Key == Key.Enter)
{
//check to ensure asbolute navigation ur, else search through bing?
//??
}
}
Upvotes: 1
Views: 2533
Reputation: 44066
Examine the URIs of search result pages on the popular search providers. Note that the search query is embedded there. Perhaps you could perform such a transformation on your search query and put it into your web control's URI?
Upvotes: 3
Reputation: 61
Build your uri: (the text will likely need some formatting to get it to fit the search site's requirements.)
string searchString = textBox.Text //format if necessary
uri = "http://www.bing.com/search?q=" + searchString;
Navigate your webbrowser control:
webBrowser.Navigate(uri);
Upvotes: 2