I am trying to create a google search with a text box. So how would I do that? I already have my web browser and stuff set up, but I am needing to now do the google search term. And to search, I want a key press down event that would then (if they press the enter key) it would search up the text in the box. How would I do this?
Asked
Active
Viewed 441 times
0
-
1please explain properly what you want? – karan Jan 31 '19 at 05:42
-
1Note that the `[visual-studio]` tag should only be used for questions about Visual Studio. – ProgrammingLlama Jan 31 '19 at 05:42
-
@karan I want to make a google search text box so users in my browser can type in like "youtube" and once you click "enter" it will search the term "youtube" on my tab control. – gr8devin23 Jan 31 '19 at 05:45
-
https://stackoverflow.com/questions/4082966/what-are-the-alternatives-now-that-the-google-web-search-api-has-been-deprecated has some options. Bear in mind google isn't the only search engine, there might be better (cheaper or easier) alternatives. – Ben Jan 31 '19 at 05:48
-
1What kind of application are you making, OP? Web? Desktop? What technologies are you working with (e.g. WinForms, WPF, WebForms, etc.)? What attempt have you made to solve this problem yourself? – ProgrammingLlama Jan 31 '19 at 05:51
1 Answers
1
[Edited]
Since you never mentioned you were developing on WPF I have edited my answer.
Make a handler that will trigger the search, and add this inside the code block:
string strUrl = "https://www.google.com/search?q=" + HttpUtility.UrlEncode(textBox.Text);
Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(strUrl);
proc.StartInfo = startInfo;
proc.Start();

Jovan
- 64
- 5
-
Should I put this in my "KeyDown" "enter" button? Since I want when you click "enter" it searches up whatever you want. – gr8devin23 Jan 31 '19 at 05:47
-
Yes, make a handler that will trigger the search and then add it inside the code block – Jovan Jan 31 '19 at 05:48
-
@Jovan will this work if OP is making a WinForms or WPF application? – ProgrammingLlama Jan 31 '19 at 05:50
-
@Jovan It is giving me these two errors. The name 'Response' does not exist in this current context. The name 'HttpUtility' does not exist in this current context. – gr8devin23 Jan 31 '19 at 05:52
-
@John nope you will need this: string strUrl = "https://www.google.com/search?q="+HttpUtility.UrlEncode(textBox.Text); Process proc = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(strUrl); proc.StartInfo = startInfo; proc.Start(); – Jovan Jan 31 '19 at 05:53
-
@gr8devin23 You should [edit your question](https://stackoverflow.com/posts/54453955/edit) with your current code. Note that Jovan's code is for web applications, not desktop applications. – ProgrammingLlama Jan 31 '19 at 05:55
-
-
@Jovan It is still giving me this one error; 'The name 'HttpUtility' does not exist in this current context' – gr8devin23 Jan 31 '19 at 05:59
-
-
Ok, it isn't giving me more errors. But it won't search anything, is there anyway I can contact you to make this easier? (such as discord) Then I could explain how you would do it on stack overflow. – gr8devin23 Jan 31 '19 at 06:04
-