Which browser do you use to surf the Internet? Basically, everyone likes to navigate the Internet using Google Chrome, Internet Explorer, FireFox, Safari, Opera and more. However, isn’t it cool if you can create your very own web browser that you can customize to your own taste? Yes, you can do that in Visual Basic 2022, and pretty easy too.
In this lesson, we shall learn how to create a simple web browser and get it running in a few minutes. First of all, start a new project and name it with any names you like, we are using the name MyWebBrowser. Change the size of Form1 to 800,600 in its properties window. Next, you need to add an engine so that your web browser can connect to the Internet, and this very engine is the web browser control, located on the Toolbox on the left side, set its size property to 600,400 and change its name to MyWebBrowser .
The next step is to insert a text box and place it at the top of the web browser control, this will be served as the address bar where the user can enter the URL. Next, place a button beside the text box and change its text as GO and change its name to BtnGo. Finally, add a few more buttons and change their texts to Home, Back, Forward, Refresh and Search respectively. The WebBrowser control comprises various methods like GoHome, GoBack, GoForward, Search, Refresh, Navigate and more. They can be used to write event-driven procedures for the various navigation buttons we place on the web browser.
For the Navigate method, we use the following syntax:
WebBrowser.Navigate(URL)
Private Sub BtnGO_Click(sender As Object, e As EventArgs) Handles BtnGO.Click MyWebBrowser.Navigate(TxtURL.Text) End Sub Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click MyWebBrowser.GoSearch() End Sub Private Sub BtnHome_Click(sender As Object, e As EventArgs) Handles BtnHome.Click MyWebBrowser.GoHome() End Sub Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles BtnBack.Click MyWebBrowser.GoBack() End Sub Private Sub BtnForward_Click(sender As Object, e As EventArgs) Handles Button1.Click MyWebBrowser.GoForward() End Sub Private Sub BtnRefresh_Click(sender As Object, e As EventArgs) Handles BtnRefresh.Click MyWebBrowser.Refresh() End Sub
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy