This tutorial will explain, how to develop a Web browser which Navigate URL in the Text Box using C#(Sharp). Text Box mentioned here is the address bar of your Web Browser. PreviousIy I have written some article about how to develop a Simple Web Browser and how to add some features to it using C# (Sharp), you can refer that for more details. You are recommended to use Microsoft Visual Studio.
We have screen shots here and have a look at it, same URL but two different blog contents, doesn’t it look annoying? When you execute the Bowser, it automatically loads Hellboundbloggers.com content and after I click on Home Button, browser loads tekkieblog content. The issue here is, it will not display the URL of tekkieblog.com in the Adress bar. When I again click on back button it loads Hellboundbloggers.com content with HBB URL in the Adress bar. There is no change in the URL because the Adress bar does not Navigate the URL and it only displays the content. So, to display appropriate URL in the Address bar while Navigating, we have to fire two events namely Text Changed Event of the Text Box and the Navigated Event of the Web Browser Control.
Text Changed Event of the Text Box
Install Microsoft Visual Studio if you haven’t. After that, right click the Text Box in the design mode and select Properties and then select events in the Properties window and move to Text Changed event and double click it.
The TextChanged event is raised when the content of the text box changes between posts to the server. Add the following code snippet.
private void textBox1_TextChanged(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
}
Navigated Event of the Web Browser Control
Right click the Web Browser control in the design mode and select Properties and then select events in the Properties window and move to Navigated event and double click it.
The Web Browser control navigates to a new document whenever one of the following properties is set or methods is called Url, DocumentText, DocumentStream, Navigate, GoBack, GoForward, GoHome, GoSearch. Add the following code snippet.
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
textBox1.Text = webBrowser1.Url.ToString();
}
In my case, Web Browser control name is webBrowser1, Text Box name is textBox1, change the Text property of the Form to any name you like. Press F5 to start the Debugging or Debug –> Start Debugging.
This article is written by Narendran. He is the founder and editor of Tekkieblog. He always strives himself to find simple solution for complex problems. If you wish to write for us, kindly check this.
Thank you bro this is really perfect 🙂 I am making a bot now I am very new about C# language but your simple browser codes are help out me. Thanx again
this is really interesting..
Interesting! But I don't know much about C# while I completed C and C++in recent semesters.
Simple but very useful feature to develop a Web browser which Navigate URL in the Text Box. Best of luck Narendran.
Superb…!!!!
Yay might try this for my bitfutura.org project 😀
A web-browser in C-language, I think I got the project for my semester exams!
Thanks! 😀
Good Luck buddy 🙂
U can refer the link : http://blog.spiharsh.com/building-webbrowser-using-c
for more elobrated steps….