webbrowser

Visual Basic .NET – Simple Web Browser


Difficulty: Beginner
Topic: Visual Basic
Screencast Included.

Learn how to create a simple web browser using Microsoft Visual Basic Express Edition 2010

VN:F [1.9.11_1134]
Rating: 5.0/5 (1 vote cast)

Before you start making your very own web browser using visual basic you need a compiler. Please read this if you don’t have the VB .NET Express Edition. http://www.itechsociety.com/2010/09/microsoft-visual-studio-express-edition/

Starting Up

MS VB 2010 EE

MS VB 2010 Express Eddition

First start up your Integrated Development Environment(IDE). In this tutorial I will be using MS Visual Basic 2010 Express Edition. Create a new Project by clicking File > New Project or ctrl + N for windows.

You will then be prompted with a new form. We will transform this simple form and make a web browser change its property according to the following:

  • Text – My Web Browser
Form Name

Form Name

If you can’t see your toolbox then in the Menu bar just click View > Other Windows > Toolbox or hit ctrl+alt+x for windows.

Web Browser Tool

Web Browser Tool

Go on to the toolbox and double click the WebBrowser tool. You will see that the WebBrowsertool will occupy the whole form.For us to resize the WebBrowser, we have to undock it from the parent container. Select the WebBrowser and then clicking the right arrow head on the top right part of the form will show you “undock in parent container” option. Click that.

Undock

Undock the Web Browser

Now click again the WebBrowser and then try to resize it according your heart’s desire using your mouse. Now change the URL property to a website that you want to visit. In this vb example I used google.com.

  • Url – google.com
Set the Url Property

Set the Url Property

We can now try this one first. But before we do that make sure that you are connected to the internet. You must now be able to visit google.com.

Web Browser Home page

Web Browser Home page

The Codes

Let’s add a new button. We will try to navigate away from google using this button. Change it’s properties according to the following:

  • Text – Go
  • Name – GoBtn

Double click the button to create a trigger. You will see that a private sub will be created for you. In between the private sub and end sub type in this code.

        WebBrowser1.Navigate("facebook.com")

You should now have something like this.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("facebook.com")
    End Sub

You can replace this line to anything website address that you want.

"facebook.com"

So if that’s perfectly navigating you away from google and bringing you to the website that you have specified, we are now ready to move one. Of course we don’t want to make a web browser that is difficult to use. We need a way to make things easier for our user to change into different websites. The solution there is the address box. The address box will serve as user input for the web address that they want to access.

The Address Bar

So to add a textbox click the textbox tool from the toolbox. Drag and drop it to our form then change the following attributes.

  • Name – addressTxt
textbox Property

Change the Textbox Property

Then go back to our button and change this line

WebBrowser1.Navigate("facebook.com")

to this

WebBrowser1.Navigate(addressTxt.Text)

This simply means that we want to navigate to what ever is the text value of addressTxt.

Now try the web browser. Go to different websites like facebook, youtube, and google.

Extra Buttons

Web Browser Navigation Buttons

Web Browser Navigation Buttons

Of course we also need a way for our users to navigate back and forward from web pages. We should also add other basic buttons like refresh and stop. So let’s try to do this.

First add 4 different buttons with the following attributes.

Button 1 Name: BackBtn
Text: Back
Size: 40, 40
Button 2 Name: RefreshBtn
Text: Refresh
Size: 40, 40
Button 3 Name: StopBtn
Text: Stop
Size: 40, 40
Button 4 Name: ForwardBtn
Text: Forward
Size: 40, 40

Next. Double click the buttons to create a new trigger and add these codes.

  1. For BackBtn
            WebBrowser1.GoBack()
  2. For RefreshBtn
            WebBrowser1.Refresh()
  3. For StopBtn
            WebBrowser1.Stop()
  4. For ForwardBtn
            WebBrowser1.GoForward()

That should work perfectly now.

Final Touches

We can now fix the overall appearance of our application. You can try to add an image for the buttons. You can found lots of cool icons here at IconArchive.

To make our program follow the size of the window, apply the following anchor attributes:

Anchor

Anchor Attribute

Web Browser Anchor : Top, Bottom, Left, Right
Navigation Buttons Anchor : Top, Left
Address Textbox Anchor: Top, Left, Right
Go Button Top, Right

Visual Basic .NET - Simple Web Browser, 5.0 out of 5 based on 1 rating

Related posts:

  1. How to – Change My Ip Address
  2. Fix Your Facebook Thumbnail
  3. Get a Compiler for C/C++
  4. HTML Tutorial 1 – Context Editor
  5. Alpha Test Update: How About a New Design?
This entry was posted in Examples, Programming, Screencast, Tutorials, Visual Basic. Bookmark the permalink.
This article is written by: chicoi08
I love making great things using my computer. From programming to designing to blogging. I enjoy doing them. I hope this website can help some people out there. View all posts by chicoi08 →

Discussion 1 Comment

  1. enigue says:

    Hi Keith, thank for all of these, keep goin’, God Bless….

    VA:F [1.9.11_1134]
    Rating: +1 (from 1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">