
HOW TO: Develop Simple Web Browser Using C# [With URL Navigating]
- Updated On 17/04/2017
- Author : Narendran.M
- Topic : Featured • Guides
- Short URL : https://hellboundbloggers.com/?p=23470
CONNECT WITH HBB ON SOCIAL MEDIA
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.
Want to discuss your queries and interact with experts? You can connect with HellBound Bloggers (HBB) Facebook group for free!
Join HellBound Bloggers (HBB) and get Instant Updates. We'll also notify you with Great Deals, Discounts and other Interesting Tips. We won't SPAM or SHARE your Email Address with anyone.
YOU CAN ALSO SEARCH FOR YOUR DESIRED TOPICS:
Thank you for reading! We welcome and appreciate your comments, but at the same time, make sure you are adding something valuable to this article. If you have any serious queries, suggestions or anything related to this article, feel free to share them, we really appreciate that.
But, if your blog comments are a random "Thank you", "Useful Post", or anything that doesn't actually upscale the article, then we'll be removing them and it won't be appeared below. Thanks for understanding and thanks for connecting with us. If you want to give us any feedback or report any errors, you can kindly contact us and we'll revert back soon.
- Comments
- Facebook Comments
-
Comments
Leave a Reply
9 Comments
Facebook Comments
Taha
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
Abhishek
this is really interesting..
Rijans -TechGainer
Interesting! But I don't know much about C# while I completed C and C++in recent semesters.
Matt
Simple but very useful feature to develop a Web browser which Navigate URL in the Text Box. Best of luck Narendran.
Vinayak
Superb…!!!!
Vishnu
Yay might try this for my bitfutura.org project 😀
Sidhant
A web-browser in C-language, I think I got the project for my semester exams!
Thanks! 😀
Hassam Ahmad Awan
Good Luck buddy 🙂
Harsha
U can refer the link : http://blog.spiharsh.com/building-webbrowser-using-c
for more elobrated steps….