This Month's Hot Topic!!!
WebBrowser - This is another great ocx control which makes programming so much fun and easy with Visual Basic. Use it to enable internet browsing right from your application! This article will show you how to do just that. A link to the example source code is available at the bottom of this page.
Start by opening a new Standard Exe project in Visual Basic. Rename the form1 of this project to frmIntBrowser and set its caption to be "Internet Browser" or whatever you like it to be. Then Add four command buttons at the top of the form and name them to be cmdBack, cmdFoward, cmdStop cmdRefresh. (Also set caption to each control depending on their name - Back, Foward, Stop and Refresh). As you might have guessed, these buttons will be used for browsing. We will add code to these buttons later. We also need a text box where we will enter the address of the site we want to visit. Add a text box, name it txtAddress and clear its Text property. Now, to be able to browse internet, here you need WebBrowser control. Go to Project - Components menu (or press Ctrl+T) and select Microsoft® Internet Controls. Close Components dialog box and new control icon should appear in your toolbox. Double click this icon, and empty white box should appear on your frmIntBrowser. Rename WebBrowser to be wb. The way i placed controls, the final window looked like this:
Let's add some code. Command button code is:
Private Sub cmdBack_Click()
The code for txtAddress control is this:
Private Sub txtAddress_KeyPress(KeyAscii As Integer)
That's basically all the code you need to browse internet with WebBrowser. Run the program, type in site address and press enter. WebBrowser will navigate to that site and show it to you. What i showed you is just a very little part of what WebBrowser control can do. Our current app is very limited in its functionality. You can add progress bar to inform the user on the progress of site downloading for example. To see much more functioniality of WebBrowser control, download this zip file (23KB) which contains a much improved Internet Browser application with QuickBrowsing, progress bar, website logging, and much more. If you don't have a program to unzip zips, download this code file (9KB).
Good luck experimenting with WebBrowser.
Made By Laimonas Simutis. 2001. email@example.com