INTRODUCTION
Well basically i've been playing around with a few functions i've learned through other tutorials and i'd like to make a tutorial on making an internet browser with history saving & Menu.
-------------------------------------------------------------------
GUI (LAYOUT)
Here is my GUI:
-------------------------------------------------------------------
What you need:
6 Command buttons with the following Names/Captions:
Command Button #1:
Name: cmdHome
Caption: Home
Command Button #2
Name: cmdBack
Caption: Back
Command Button #3
Name: cmdForward
Caption: Forward
Command Button #4
Name: cmdStop
Caption: Stop
Command Button #5
Name: cmdRefresh
Caption: Refresh
Command Button #6
Name: cmdGo
Caption: Go
1 ComboBox with the following Name/Caption (Caption is the same as Text... Just find "Text" in the properties window):
Name: cboURL
Caption/Text: (Nothing)
1 Label with the following Name/Caption:
Name: lbCaption
Text: Address:
1 Web Browser with the following Name:
Now for the web browser, you'll need to add the component:
"Microsoft Internet Controls" You can get to the components window by press CTRL+T on the keyboard, then scroll down and tick "Microsoft Internet Controls".
After doing the above procedures, there should be a new item on the list of the tool bar. It looks like the Earth. Now click on it and drag it onto your Form, make it big because it's what you'll be using to view pages with.. Use this Name:
Name: wWeb
If you're having problems like an error when you click "Microsoft Internet Controls" just PM me and i'll help you out.
----------------------------------------------------------------
CODE WITH EXPLANATIONS!
Add this code to cmdHome button (Double click on the Home button to bring up code window.
Quote:
Private Sub cmdHome_Click()
wWeb.GoHome
End Sub
|
This makes the web browser (wWeb) go to the home page when you click the "Home" button.
(The home page for me is Google, i think it jsut uses your other browser's home page...)
----------------------------------------------------------------
Quote:
Private Sub cmdBack_Click()
wWeb.GoBack
End Sub
|
This makes the web browser (wWeb) go to the previous page whenever you click the "Back" button.
----------------------------------------------------------------
Quote:
Private Sub cmdForward_Click()
wWeb.GoForward
End Sub
|
This code instructs the web browser to go to the subsequent page when you click the "Forward" button.
----------------------------------------------------------------
Quote:
Private Sub cmdGo_Click()
wWeb.Navigate (cboURL.Text)
cboURL.AddItem (cboURL.Text)
End Sub
|
Okay, it's getting a bit harder now.
The above code makes the web browser (wWeb) go to the page specified by the cboURL box (ComboBox).
AND also whatever is entered into the cboURL box is also added to the drop down arrow box (like history).
----------------------------------------------------------------
Quote:
Private Sub cmdRefresh_Click()
wWeb.Refresh
End Sub
|
This refreshes the web browser when you click the "Refresh" button.
----------------------------------------------------------------
Quote:
Private Sub cmdStop_Click()
wWeb.Stop
End Sub
|
This code stops the web browser in it's tracks! Basically just stopping it from loading any further.
----------------------------------------------------------------
MENU + CODES
Ok to add a menu to the form you need to go to Tools>Menu Editor or just press CTRL+E.
A window like this will pop-up:
Now add the following in:
Quote:
Caption: File
Name: mnuFile
|
----------------
Then press "Next"
And then press the Right-Arrow key to make the 3 dots appear:
Add this in:
Quote:
Caption: Print
Name: mnuFilePrint
|
------------------
Then press "Next"
(Let 3 dots appear):
Quote:
Caption: Exit
Name: mnuFileExit
|
------------------
Press "Next" again.
(This time take away the 3 dots by pressing the left arrow key)
Quote:
Caption: Edit
Name: mnuEdit
|
----------------
Press the "Next" button again!
(And make the 3 dots appear again by pressing the right-arrow key)
Quote:
Caption: Move
Name: mnuEditMove
|
---------------------
Press the "Next" button again!
(Keep the 3 dots):
Quote:
Caption: Resize
Name: mnuEditResize
|
----------------------
MENU CODE
Quote:
'Invoke PrintForm method for this Form (Me)
'Sends image of Form to printer - useful for hardcopy
Private Sub mnuFilePrint_Click()
Me.PrintForm
End Sub
|
Basically just prints off the page.
----------------------------------------------------------------
Quote:
Private Sub cboURL_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
wWeb.Navigate cboURL.Text
End If
End Sub
|
This is an essential code to make the "History" function work.. It makes history work.. Lol.
----------------------------------------------------------------
Quote:
Private Sub mnuFileExit_Click()
End
End Sub
|
Closes the program.
----------------------------------------------------------------
Quote:
'Invoke Move method for this Form (Me)
'Look at Form object --> Methods in Help
Private Sub mnuEditMove_Click()
Me.Move 0, 0
End Sub
|
Moves the program window.
----------------------------------------------------------------
Quote:
'Parameters of move are: left edge, top edge, width, height
'Measurements in twips (see Lesson 7)
Private Sub mnuEditResize_Click()
Me.Move 6000, 6000, 6000, 5000
End Sub
|
Resizes the program.
And if you're lazy and just want the full code:
Quote:
Private Sub cboURL_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
wWeb.Navigate cboURL.Text
End If
End Sub
Private Sub cmdBack_Click()
wWeb.GoBack
End Sub
Private Sub cmdForward_Click()
wWeb.GoForward
End Sub
Private Sub cmdGo_Click()
wWeb.Navigate (cboURL.Text)
cboURL.AddItem (cboURL.Text)
End Sub
Private Sub cmdHome_Click()
wWeb.GoHome
End Sub
Private Sub cmdRefresh_Click()
wWeb.Refresh
End Sub
Private Sub cmdStop_Click()
wWeb.Stop
End Sub
Private Sub Form_Load()
Dim Response As Integer
Response = MsgBox("Open Program?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
MsgBox "Welcome to Trav's Internet Explorer!"
Load Me
ElseIf Response = vbNo Then
Me.Refresh
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer!"
Unload Me
ElseIf Response = vbNo Then
Me.Refresh
End If
End Sub
'Invoke Move method for this Form (Me)
'Look at Form object --> Methods in Help
Private Sub mnuEditMove_Click()
Me.Move 0, 0
End Sub
'Parameters of move are: left edge, top edge, width, height
'Measurements in twips (see Lesson 7)
Private Sub mnuEditResize_Click()
Me.Move 6000, 6000, 6000, 5000
End Sub
Private Sub mnuFileExit_Click()
End
End Sub
'Invoke PrintForm method for this Form (Me)
'Sends image of Form to printer - useful for hardcopy
Private Sub mnuFilePrint_Click()
Me.PrintForm
End Sub
|
----------------------------------------------------------------
EXTRA
You can also add extra message boxes to the exit buttons just in case you accidentally press Exit.
Here is the code:
Quote:
Private Sub mnuFileExit_Click()
Dim Response1 As Integer
Response1 = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
If Response1 = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer."
Unload Me
ElseIf Response1 = vbNo Then
Me.Refresh
End If
End Sub
|
----------------------------------------------------------------
Or:
Quote:
Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer!"
Unload Me
ElseIf Response = vbNo Then
Me.Refresh
End If
End Sub
|
----------------------------------------------------------------
Or jsut simply:
(Put this code between the Private Sub "?"_Click ()
and End)
(The "?" stands for the button name... Put the button name in, whatever it is)
----------------------------------------------------------------
THANKS:
Thanks to Tcm9669 for the original Screenshot program.
Thanks to TheComputerMaster for the updated "hidden" version of the Screenshot program.
And thanks to you for taking the time to read this awfully long tutorial.
This tutorial was made by me, Travy92.
Samples!! WOOH!: