Total Pageviews

Tuesday, September 20, 2016

Create Simple Web Browser in Visual Basic 2015

Creating a Web Browser in Visual Basic 2015 is very easy task. Even if you are a novice in Visual Basic 2015 following the steps in my post you will be able to create it.

1) Open the Visual Studio 2015 and create a new Visual Basic 2015 project.

2) Second, go in the right bottom corner in Properties and find WindowsState. Change WindowsState in Maximized. That means when you start the application will start as maximized.

3) Little bit change the width and the height of the form. Make it wider and higher.

4) I suggest inserting a panel that will be docked on Top. This is because by default WebBrowser control will cover the entire form or if you dock it maximum will be little bit more than the half form. This will not give good look of the application.

So, go in Toolbox and choose Panel.

After you insert it in the form you will get the following.
 
Now let dock it. Click on the panel and go in the right bottom corner in Properties. Find Dock and change it from None to Top.

Now you will have the following view.

In this panel we will insert the buttons: Navigate, Refresh, Back and Forward.

5) Insert 4 buttons in the panel and put the following properties for each of them!

Button1 - .Name = btnNavigate ;  .Text = Navigate
Button2 - .Name = btnRefresh ;  .Text = Refresh
Button3 - .Name = btnBack ;  .Text = Back
Button4 - .Name = btnForward ;  .Text = Forward

After you inserted everything you will have the following view.



6) Now insert WebBrowser control from the Toolbox. Insert it bellow the panel.

I believe you noticed that immediately after you inserted the WebBrowser control, the control automatically docked up to the panel. That's why we inserted the panel.

7) Now we need a TextBox control to use it as an URL place to put for navigation. After I reorganized everything we have the following view.

8) Let write the code for each of the buttons!

    Private Sub btnNavigate_Click(sender As Object, e As EventArgs) Handles btnNavigate.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub

    Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        WebBrowser1.Refresh(TextBox1.Text)
    End Sub

    Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub btnForward_Click(sender As Object, e As EventArgs) Handles btnForward.Click
        WebBrowser1.GoForward()
    End Sub

1 comment:

  1. If you want the Visual Studio Project in rar format write me in the contact form and I will send it to you in e-mail.

    ReplyDelete