Shane-
6th October 2006, 12:39 AM
For this we'l be using the WebBrowser Control (shdocvw.dll)
Open VB
Double click "Standard EXE"
That sould load your form (Form1)
In the bottom right hand corner, you sould have a box called "Properties"
At the top of that box, there is " (Name) ", Type in there: frmMain
frm = Its a form we'r naming
Main = We give it the name of Main as it will be our main form.
Now we've renamed the form, Take a look at your form, Bottom right hand corner there sould be a small blue box, Click and hold your mouse over that, And drag it (That will resize your form), Resize it to a size you feel suitable.
Now to add a WebBrowser.
Click " Project " then "Components"
http://img227.imageshack.us/img227/6307/vbtk9.png
Scroll down the list untill you find: Microsoft Internet Control.
Tick that and click "ok"
On the left hand side, You now sould have a "World" logo, That is your WebBrowser Control.
Select it, And drag/drop it onto your form, Use the same meathod i told you to about resizing the form, To resize the browser
(Leave about 10-20% of top of the form showing)
Now, You rember how we renamed the form to " frmMain "... Do that with the WebBrowser, And call it " IE "
Congraz, You have a large percent of the form done.
Double click the form (Gray part) and you sould acces the "Code Area", All you sould be able to see is:
Private Sub Form_Load()
End Sub
In the middle of those 2 lines, Add:
Me.Caption = "Gua Browser" 'Renames the titelbar
IE.Navigate "www.google.com" 'Navigates your browser
IE.Width = Me.ScaleWidth 'Changes width of your browser
IE.Left = 0 'Alines your browser
IE.Top = 800 'Gives up anought room at top of form for buttons
IE.Height = Me.ScaleHeight 'Changes the height of your browser
The green comments example what each line does.
Now to test your browser,
http://img141.imageshack.us/img141/5212/vbdw7.png <-- Shows
Now to give it a little life.
Double click "frmMain" in your Project browser (Top right corner) so your able to see your form again
On the left hand side, You sould see your "controls" hover over each of those to see what there are, When you find 'CommandButton', Drag and drop that into your form like you did with the Browser control
Now to the same with 'Textbox'
Place the TextBox and Button like:
http://img182.imageshack.us/img182/3940/vbst4.png
This will be your address bar, and your " Go " button
You rember how to give things names?... I hope so because im not telling you again
Name the Button: cmdGo
Name the Textbox: txtAddress
In the Properties menu, theres other options (To give captions to controls)
For the button, Find "caption" and type in ' Go! ", And for the Textbox, type in ' Google.com '
Double click your 'Go' button, and you'l see
Private Sub cmdGo_Click()
End Sub
In the middle of there, Enter:
On Error Resume Next 'If there is any errors, The project wont crash
IE.Navigate txtAddress.Text 'Navigates your browser to the giving site
Now double click the textbox (txtAddress)
You have:
Private Sub txtAddress_Change()
End Sub
Take a look at: http://img91.imageshack.us/img91/9031/vbfh3.png
First, We'r going to do the red one, Click " Click ", That will give you
Private Sub txtAddress_Click()
End Sub
Enter in there:
txtAddress.Text = "" 'This is to clear the textbox so we can enter a new URL
Now the blue one (KeyDown), That gives:
Private Sub txtAddress_KeyDown(KeyCode As Integer, Shift As Integer)
End Sub In the middle, Add
If KeyCode = vbKeyReturn Then IE.Navigate txtAddress.Text 'This is so when we hit enter on the keyboard, It takes us to the site, Aka saves pressing "go"
Now we have a basic brower set up... Now we need a " Back ", " Forward ", "Home" button... You know how to make those :-)
Put them under the address bar (And make it look nice), Rember to give them the right names...
Back = cmdBack
Forward = cmdForward
Home = cmdHome
Double click Back, and enter the code:
On Error Resume Next 'Provents any error
IE.GoBack
And double click Forward and enter:
On Error Resume Next 'Provents any error
IE.GoForward
And double click Home and enter:
On Error Resume Next 'Provents any error
IE.GoHome 'Goes to your IE home page
Okie, Now we have done:
Navigate
Home
Back
Forward
We need 2 more buttons, cmdRefresh and cmdStop
cmdRefresh
On Error Resume Next
IE.Refresh
cmdStop
On Error Resume Next
IE.Stop
Ok, Basic Front Done
Double click your browser, You'l get
Private Sub IE_StatusTextChange(ByVal Text As String)
End Sub You rember how we changed the textbox "Change" to "Click"... We'r doing that again, Change StatusTextChange to DocumentComplete, which will give you:
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
End Sub
This is the Document Complete" function, when the browser has finished loading a page, This function is called.
Add: Me.Caption = "Gua Browser - " & IE.LocationName
That will change the title bar off the program to " Gua Browser - " then the name of the page your on, Like Firefox and IE do
Well... I think that covers the basics off making a small web browser
Codes at: http://www.shane.webwise-uk.com/projects/GuaBrowser.rar
Shane
Open VB
Double click "Standard EXE"
That sould load your form (Form1)
In the bottom right hand corner, you sould have a box called "Properties"
At the top of that box, there is " (Name) ", Type in there: frmMain
frm = Its a form we'r naming
Main = We give it the name of Main as it will be our main form.
Now we've renamed the form, Take a look at your form, Bottom right hand corner there sould be a small blue box, Click and hold your mouse over that, And drag it (That will resize your form), Resize it to a size you feel suitable.
Now to add a WebBrowser.
Click " Project " then "Components"
http://img227.imageshack.us/img227/6307/vbtk9.png
Scroll down the list untill you find: Microsoft Internet Control.
Tick that and click "ok"
On the left hand side, You now sould have a "World" logo, That is your WebBrowser Control.
Select it, And drag/drop it onto your form, Use the same meathod i told you to about resizing the form, To resize the browser
(Leave about 10-20% of top of the form showing)
Now, You rember how we renamed the form to " frmMain "... Do that with the WebBrowser, And call it " IE "
Congraz, You have a large percent of the form done.
Double click the form (Gray part) and you sould acces the "Code Area", All you sould be able to see is:
Private Sub Form_Load()
End Sub
In the middle of those 2 lines, Add:
Me.Caption = "Gua Browser" 'Renames the titelbar
IE.Navigate "www.google.com" 'Navigates your browser
IE.Width = Me.ScaleWidth 'Changes width of your browser
IE.Left = 0 'Alines your browser
IE.Top = 800 'Gives up anought room at top of form for buttons
IE.Height = Me.ScaleHeight 'Changes the height of your browser
The green comments example what each line does.
Now to test your browser,
http://img141.imageshack.us/img141/5212/vbdw7.png <-- Shows
Now to give it a little life.
Double click "frmMain" in your Project browser (Top right corner) so your able to see your form again
On the left hand side, You sould see your "controls" hover over each of those to see what there are, When you find 'CommandButton', Drag and drop that into your form like you did with the Browser control
Now to the same with 'Textbox'
Place the TextBox and Button like:
http://img182.imageshack.us/img182/3940/vbst4.png
This will be your address bar, and your " Go " button
You rember how to give things names?... I hope so because im not telling you again
Name the Button: cmdGo
Name the Textbox: txtAddress
In the Properties menu, theres other options (To give captions to controls)
For the button, Find "caption" and type in ' Go! ", And for the Textbox, type in ' Google.com '
Double click your 'Go' button, and you'l see
Private Sub cmdGo_Click()
End Sub
In the middle of there, Enter:
On Error Resume Next 'If there is any errors, The project wont crash
IE.Navigate txtAddress.Text 'Navigates your browser to the giving site
Now double click the textbox (txtAddress)
You have:
Private Sub txtAddress_Change()
End Sub
Take a look at: http://img91.imageshack.us/img91/9031/vbfh3.png
First, We'r going to do the red one, Click " Click ", That will give you
Private Sub txtAddress_Click()
End Sub
Enter in there:
txtAddress.Text = "" 'This is to clear the textbox so we can enter a new URL
Now the blue one (KeyDown), That gives:
Private Sub txtAddress_KeyDown(KeyCode As Integer, Shift As Integer)
End Sub In the middle, Add
If KeyCode = vbKeyReturn Then IE.Navigate txtAddress.Text 'This is so when we hit enter on the keyboard, It takes us to the site, Aka saves pressing "go"
Now we have a basic brower set up... Now we need a " Back ", " Forward ", "Home" button... You know how to make those :-)
Put them under the address bar (And make it look nice), Rember to give them the right names...
Back = cmdBack
Forward = cmdForward
Home = cmdHome
Double click Back, and enter the code:
On Error Resume Next 'Provents any error
IE.GoBack
And double click Forward and enter:
On Error Resume Next 'Provents any error
IE.GoForward
And double click Home and enter:
On Error Resume Next 'Provents any error
IE.GoHome 'Goes to your IE home page
Okie, Now we have done:
Navigate
Home
Back
Forward
We need 2 more buttons, cmdRefresh and cmdStop
cmdRefresh
On Error Resume Next
IE.Refresh
cmdStop
On Error Resume Next
IE.Stop
Ok, Basic Front Done
Double click your browser, You'l get
Private Sub IE_StatusTextChange(ByVal Text As String)
End Sub You rember how we changed the textbox "Change" to "Click"... We'r doing that again, Change StatusTextChange to DocumentComplete, which will give you:
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
End Sub
This is the Document Complete" function, when the browser has finished loading a page, This function is called.
Add: Me.Caption = "Gua Browser - " & IE.LocationName
That will change the title bar off the program to " Gua Browser - " then the name of the page your on, Like Firefox and IE do
Well... I think that covers the basics off making a small web browser
Codes at: http://www.shane.webwise-uk.com/projects/GuaBrowser.rar
Shane