3/22/11

Creating a Web Browser in VB.Net

?????This was the first thing I ever learned in VB i was completely honest i don't know why but if i learned it at the start anyone can do it. Ok lets get started.

1)File >new project>windows application (name it web browser or what ever)
1.)Posted Image


2) Make screen size to any size but big enough to see an entire web browser.

3) Add a Panel and dock it to the top (when clicked on the panel. Properties window on the right “Dock" )
3.)Posted Image

*Docking it
*Posted Image


4) Personally i don't like the default color but that is not important but if you insist on changing the color...
Posted Image




5)I have made many of these web browsers in the past just to keep it refreshed in my memory because if you do it right it can be a fun tool. So I created Back, Forward, Refresh and a GO! Button The attachment at the bottom of the page if you can’t be bothered making your own or you can just us Labels (basic text).

5) Add a text box and a buttons to the panel
5.) Here’s what i got so far >
Posted Image



6) I got the colors to change on the text box in the properties menu, thats not important i just did it for style.


7) Web browser. Just drag and drop it
7.)Posted Image


*ok don't rename anything ( you can change the text but NOT the name unless you change the coding) e.g. Say *originally it was " textbox1" and you rename it "Type here" you would have to put "Typehere.Text" understand? )

*double click the button so it opens the code window

1    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
2         
3WebBrowser1.Navigate(TextBox1.Text)
4    End Sub


Now I didn’t rename the picture boxes and i double clicked them to open in code window starting with Back>refresh>forward>go


1Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
2        WebBrowser1.GoBack()
3    End Sub


1Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
2        WebBrowser1.GoForward()
3    End Sub



1Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
2        WebBrowser1.Refresh()
3    End Sub


So you can just copy and past the code its that easy

Here’s what the finished web browser will look like in Debug mode

**You can also make a homepage easily by changing the URL value in the properties window just click the web browser we added earlier and the properties will change fo r that specific item
Posted Image




Here is the finished product running.

Posted Image



The buttons i made are in a .zip attachment

Understanding it

// Webbrowser1 is the name of the web browser item which we added when we were designing.
\\ Navigate is the command which tells the web browser to go to a specific web page as PictureBox4_Click (picture box 1 being my go button i designed and when you click it, it navigates to the web page


All the rest e.g. go back, go forward are straight forward


01Public Class Form1
02
03  
04
05
06    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
07        WebBrowser1.GoBack()
08    End Sub
09
10    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
11        WebBrowser1.GoForward()
12    End Sub
13
14
15    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
16        WebBrowser1.Refresh()
17    End Sub
18
19
20    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
21        WebBrowser1.Navigate(TextBox1.Text)
22
23
24    End Sub
25
26End Class

0 التعليقات:

Post a Comment

Related Posts Plugin for WordPress, Blogger...