Wednesday, February 1, 2012

Creating A Simple Web Browser


Today I'm going to show you how to make a simple web browser with all the basic features like home back forward refresh ect...

So to get started you with our web browser make a new windows forms application and name it MyWebBrowser or whatever you want.

OK now add a new Tool Strip to the top of the form(Tool Strip can be found in the tool box in the menu and toolbars tab) OK now add a Web Browser to the center of the form and size it to the size you want.(Web Browser is at the very bottom of the common controls tab in the tool box)

OK now we need some buttons for our form so click on the Tool Strip you placed on the top of the form and there should be a little blue box that pops up left click it and a picture button will pop up do this intel you have 5 picture buttons. Now click the little arrow on the Tool Strip add thing and select text box then add one more picture button.

Now right click the text box and goto properties and change the name to URLBox and the text to URL then scroll down and find the size setting and change the width to a size according to your form.

So now your form should look like this:

 

Now right click one of your picture buttons and go to properties and find the image setting and change the image to what you want. Repeat for the rest and you'll have:


Now right click the web browser and goto properties and set it's name to webBrowser and it's URL to a web site like Google or something.

OK now for some actual code.

Double click the back button on the tool strip and add this code.
Code:
webBrowser.GoBack();
That does exactly what you would think it does.

OK double click the forward button on the tool strip and add this code.
Code:
webBrowser.GoForward();
Now double click the home button on the tool strip and add this code.
Code:
webBrowser.GoHome();

Now double click the stop button on the tool strip and add this code.
Code:
webBrowser.Stop();
Then double click the refresh button on the tool strip and add this code.
Code:
webBrowser.Refresh();
Now the last thing we need to do is make our address bars text usable for the web browser to navigate with.

So what we do is add code to our Go button.
Code:
webBrowser.Navigate(URLBox.Text);
(tip don't forget http:// when typing in the address bar)

Congratulations you just made your own web browser.
I hope you enjoyed this tutorial, as always +rep and comments/questions are welcome.
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.





No comments:

Post a Comment