A VB.net 2008 Web Browser!
Aug 16
Creating a VB.net web browser is an extremly simple task. So much so that it’s a great way to introduce yourself the the language. We shall be using the full version of Visual Basic .Net 2008, but the express editions will work Perfectly fine. Let’s get started shall we?
First open VB and create a new Windows Forms Application. You should name your application something that is easy to remember so you don’t forgot what the folder is called, in this example I shall name it, creatively, browser.
Now you should have a empty .Net window. Here we shall start designing our browser. Using the toolbox on the right (if you can’t see the toolbox you
can open it with control, alt and x) we want to drag over the ‘Web Browser’ Control, contained in the Common Controls box. By default the Web Browser control will take up the whole application, we want to undock it so click the browser once and find the small arrow on the top right (see image below)
And then click the ‘Undock in Parent Container’. Now we can grab the edges of the web browser control and change it’s size. Ideally we want something the web browser to leave 60 pixels on the top of the windows application. Think about the browsers you’ve used and leave that amount of space for a toolbar. When you have the size of the browser window you want we need to make it expand when the main window expands. We do this by clicking once again on the browser window, then on the right looking in the properties menu and finding anchor. Here we click the drop down box and select the bottom, left and right and top. This will force the browser to expand to the right, left, bottom and top when the main window expands. Without this the browser would just stay the same size.
Now in the space above the browser window we want to drag a Panel. You can catch the panel in the toolbox section, containers. A panel will enable us to collectively manage it’s objects, while also helping in the aspect of design. Resize the panel to hit each of the main windows edges and the very top of the browser element. You can use the arrow keys on the keyboard to align the panel. Once again we want to anchor the panel. This time we want to anchor to the top, right and left. We should now have something very much alike to what’s below
Now we want users to be able to navigate the browser to certain locations using an address bar. To insert a bar using the toolkit drag a text box into our top container. You can find the text box control in the toolbox, common controls section. We want to move the text box control to the very bottom of our container panel and expand it’s size to around 466 pixels. In the right properties menu we want to rename this text box to navbox.
Now we need to give the user something to click when he has entered the web URL, so for this we’re going to insert a button. We can once again find the button in the common section of the toolbox. Place this button next to the navigation text box. Rename the button searchbutton, then in the properties menu find the ‘Text’ element and type ‘Go’. For design aspects we will change this buttons flatstyle (once again in the properties menu) to Popup. Now resize the button to be as high as your text box.
Ok I’m sure you want to start coding now so let’s quickly move on to making your collection of form items into a browser! Double click on the Go button you’ve created and we should now be shown the code screen.
VB.net 2008 will automaticlly create some code because you double clicked on the code button, and our cursor should be contained within the Private Sub section of code. Here is where we shall start coding.
WebBrowser1.Navigate(navbox.Text)
Lets explain the above simple but powerful code. We first type WebBrowser1 which is the name of the web browser control we dragged onto the application earlier now we call a properties of the control, in this case we want to navigate the browser window, so, as one would expect we type navigate. Now we use brackets to define the value that we want to send the control. If you wanted to the browser to go to one set location you would use quation marks and then a url, for example
WebBrowser1.Navigate(“http://google.com”)
for example However we want to accept use input from our text box. Because we named this textbox navbox we can call it’s value using navbox.text. This means whatever is in the navbox at the time of the user clicking the button will be used as the value. Because it’s not a text string within the code we do not use the quotation marks.
You can now test your browser to see if you can navigate!
If all went well you will be able to navigate to any website. Because it uses the IE control if the user has flash installed the browser will be able to view flash, and do many more things IE can do. Of course our browser is not the most exciting yet is it? Lets add a few more important features for any browser!
First of all lets tackle the all important back button. Without back buttons people will be stuck on certain pages and they would not be able to use the browser effectively at all. For the back button we’re going to add yet another button the the browser, this time above the navigation box. We shall name this button backbutton and have it’s text value as ‘Back’. We shall also add a icon for a better cleaner look. To add a icon we shall click the button once and click the properties window, then find the image option. Click the … next to image which will bring up a window saying select resource and then click the import button and find your back image file. For best results use a 24×24 PNG Transparent button (I use this fantastic one). You now will need to change the TextImageRelation to ImageBeforeText. Now repeat these steps replacing back with forward and TextImageRelation to TextBefore Image.
Let’s get to coding these buttons. Double click the back button to once again return to the code window and type WebBrowser1.GoBack(), do the same for the forward button but replace GoBack with WebBrowser1.GoForward(). That’s all for this sort tutorial, on request I will expand with more features such as a search box, I would love to hear your input!
Sep 30 at 19:14
Thanks men this helped me out. DO you know anything about queries in VB.net ?
Oct 01 at 10:27
this was very helpful
Oct 02 at 22:30
very good.
Oct 03 at 11:48
how do you create a search box so when you type in the key words in a text box and click a search button it come up like in google or something and how do you create a dropdown history on the navbox
this will help me out a lot
cheers
Oct 07 at 16:58
very nice tutorial helped alot =P
Oct 16 at 20:20
Thanks for the easy code. Could you explain more features for me?
Thanks
Oct 31 at 08:00
Thanx for the code.its really very helpful.could u explain more tools.how they work.
Thanx
Nov 15 at 05:10
How could I make it where it uses my VPN connection instead of the client machines internet connection? I want them to use my custom web browser app, but I want the internet traffic go thru my gateway thru the VPN and not thru their local internet connection.
thanks
mike
Nov 17 at 12:05
amazing tutorial , very helpful .
but 1 thing , how do i make the go button work with just pressing the ‘ENTER’ button.
thanks
Dec 04 at 18:26
Thanks! This was easy to read and helpful.
Dec 18 at 20:48
Interesting tutorial, Would you create some more advanced features too such as options to clear cookies / Cache as well as a bookmarks function
Dec 25 at 20:30
I don’t get the Go button part, and desperately need help. I don’t know any code.
Dec 27 at 00:55
Same with ali how do make the go button work with pressing the Enter button?
Dec 28 at 16:19
This helped with my programming project, thanks
Jan 01 at 08:52
Loved this.
Extra feature needed:
How to update the navbox to show th current URL?
Thanx for this part.
Jan 11 at 01:13
but how would you assign keyboard shortcut like if you press enter it will navigate the work for the go button?
Jan 30 at 12:36
fantastic simple as that
Feb 05 at 05:43
i love you man,i was looking for the back code all over the web.thank you alot.i could kiss u…
good work
Feb 22 at 03:58
the tutorial was a real good help to get on the right way.
i would like to know about adding security features to it.
thanx.
Mar 11 at 17:51
Hi, This is a very good, but basic tutorial. I have actually made money broadcasting my Web browser to various private sources.
For any querys on what code I use, please contact
miczaweb@yahoo.com
I will distribute SOME of my source code for free, on request.
Mar 12 at 10:19
you can set the form properties Accept Button as Go Button or just type on go button webbrowser1.nevegate(textbox1.text)
Mar 12 at 11:24
Very good tutorial! Write more!
Mar 13 at 15:41
how do you make a search for the current displayed html doc..
ie is the word “rocketship” on the displayed page?
i want to have script perform the function of pressing “ctrl F”
i have a list box.. if i select a text in the listbox i want the program to “CTRL F” for the selected text.. in the open browser window. in effect duplicating the CTRL F .. “find” function on web browsers.. but instead of having to type in keywords.. it uses as only input.. the click on the listbox.
Apr 04 at 08:07
That was very clear and simple.
Thanks a LOT
Apr 14 at 14:41
I’d like to be able to do many more advanced things, such as deleting browser history, manage/use favorites, other things standard to other Web Browsers, like IE.
Apr 27 at 02:08
hello
thank you
i’d like to add the following commands
back
WebBrowser1.goback()
forward
WebBrowser1.goforward()
refresh
WebBrowser1.refresh()
home
WebBrowser1.gohome()
i need to know hot to make it recognize webpage title and address
and use the right click to open a nw page in the same window
please send the way to info@yanbuhost.com
Jun 02 at 06:14
hey how do you creat it so when you right click on a link and open new window that it uses the browser you created instead of opening in a new window also want to learn how to create a menu so you can save/make a favorites options and along with so it automatically remembers what web sites you have been with thanks.
and if possible a push in the right direction on how to create it so it runs of its own back, iw not using windows explorer to run it
maxjones174@hotmail.com
Jul 09 at 05:03
nice tutorial .. refresh my memory in programming for so long .. tnx a lot more feature would be great !
Aug 05 at 08:05
hey you must change the name of form……… i did it for myself
Aug 21 at 09:22
Hi, I need your help regarding webbrowser.
I want the user to be able to type text in webbrowser control and also set and format,color,bold etc u know HTMl does thiis for us. How i achieve this functionality. Also performance is the main cosideration. Typing of text shuld be fast as curreently when i type text, it takes alot of time on slow machine to b view. may b bcoz of any buffering etc. Can u Help ?
Sep 16 at 01:23
Thanks. Very helpful. Sample code works with 0 error messages.
Same question as “max”: How to avoid Windows Explorer from opening when clicking certain links but instead running in the same Web Browser?
Sep 29 at 07:19
This tutorial is very useful for it. But it some implementation is required.
Oct 07 at 16:11
P.S. you cant program the code of a browser control, just the components that navigate it. To answer max’s question.
Oct 14 at 10:58
I agree, it needs a few extra functions, but this is a very good tutorial
. I commend you for the excellent tutorials that you write. A refresh/stop feature would be good though.
Oct 14 at 11:04
*Edit: Also, how would we make the form name change according to the page that we may be viewing? For example, YourWebsiteTitle – Browser Name. *Add: WIN! I got a stop button working. Just create a stop button with a symbol or what not, then double click it to open the scripts menu. Then type in the code “WebBrowser1.Stop()” and it should work
Oct 14 at 11:17
*Same with the Refresh button, but instead of “WebBrowser1.Stop()”, it’s “WebBrowser1.Refresh()”
Have fun VBing
Nov 29 at 21:55
This is very helpful. I would be very curious how to add a couple of more features like you mentioned, one “search” and also “tabs”.
When clicking a link within a page it opens IE (default browser)
Thanks
Feb 12 at 15:16
thanks 4 easy code
i want to know about search box
Feb 25 at 05:36
Awesome tutorial, written out very well in an easy to understand manner. Thank you!
Mar 05 at 16:48
You want to learn how to use it’s correctly, it’s is short for IT IS not the possessive ITS.
Jun 15 at 04:48
This Really very nice Technique to make a Web Browser in VB . NET.
Thankx a lot by bottom of mu heart
for giving me this Information
Jun 15 at 04:51
Yes It is very nice code for making a gooood Browser.
But it will very gooooood if v implement it for furthur technique and designed 4 better use
More technique required
Thanx a lot
Jun 15 at 04:57
Plz Tell me
How Can i Make Such browser which open new site without opening new windows and open it in new tab
Send me it on ziyad_kagzi@yahoo.com
Aug 10 at 05:27
this is vey vey simple do you think to update this
Aug 18 at 08:36
hello!
mr genius,
i would like to say thanks to u,, coz u had job , can u tell to display the record in gridview from database table..
hope u have an answer abt my qus,,
hop u vill send the solution to my mail,,
anxiously waitng for ur reply
Sep 30 at 12:36
hi
that was very gud but how can i create a browser
that will open new tabs…thankx
Nov 12 at 16:52
Thanks for this, its all helpful, especially the icons. Please help me out with these: How to search the web from a textbox in the form, and how to make the navigation textbox show where address of the site that it has gone to, if you haven’t typed it manually, like the way browsers update themselves when navigating
Email me on kariukimatthew@live.com
Jan 05 at 04:52
I want to create a web browser with few requirements could u plz help me ????
1) it has to open a spec site only defined by me eg:microsoft.com
2) i want to disable right click address bar nd all stuff i want it all automatic only microsoft.com should open rest all domains i want block
3) i want to hide or overwrite the spec part of data eg:the name microsoft.com
reply required plz help…….
Jan 25 at 15:37
Thank you veru much. I’ve been doing programming at school and this has helped me a lot. I would prefer it if you could add on a few more features such as loading/progress bar etc. Thank you anyway!