• (2 Pages)
  • +
  • 1
  • 2

Create a WebBrowser Step-by-Step Tutorial

#1 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Posted 29 July 2008 - 10:24 AM

In this Tutorial I will show you how to create your very own webbrowser.

You will need: 1 Toolstrip + ToolStrip Controls(explained later), 1 WebBrowser.

First thing is first, drag a toolstrip from the toolbox onto the form. Make sure that the Grip Visibility is set to Hidden.

Posted Image

Now we will add the controls. You will need:(6 ToolStripButtons, 1 ToolStripLabel, and 1 ToolStripTextBox). Now we will set the names of the controls. The first button will be called back, the second forward, the third refresh, the fourth stop, the fifth home and the last GO. For the GO button set the alignment property to right. Now that you have the names we can set each of the button's DisplayStyle to Image. Set the proper images for each button. Now we will name the label and the textbox on the toolstrip. For the Label set the text property to URL: and the name to urlLabel. Now the textbox will be named url and the text leave blank.


Next drag the WebBrowser Control onto the form.

Posted Image

Set the name property of the webbrowser to webBrowser

Now for the coding.

Double-Click on the Form and enter this code webBrowser.GoHome();.
Double-Click on the Back Button and enter this code webBrowser.GoBack();.
Double-Click on the Forward Button and enter this code webBrowser.GoForward();.
Double-Click on the Refresh Button and enter this code webBrowser.Refresh();.
Double-Click on the Stop Button and enter this code webBrowser.Stop();.
Double-Click on the Home Button and enter this code webBrowser.GoHome();.
Double-Click on the GO Button and enter this code webBrowser.Navigate(url.Text);.
Double-Click on the webBrowser and enter this code url.Text = e.Url.ToString();.

This is what your final design should look like.

Posted Image

Now run the form and have fun!

Attached File(s)



Is This A Good Question/Topic? 1
  • +

Replies To: Create a WebBrowser

#2 dExIT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-May 09

Posted 16 May 2009 - 10:46 AM

Thx, for this realy usefull tutorial, but i have questions :

1) How to lock the URL bar, for example, when the WebBrowser opens, it opens a website defined in the program's code, and shows the Adress in the URL bar, BUT the user cannot edit it...
1.1) Or how to remove the URL bar, but make the Browser start with a default start page ... like in IE its about:blank or whatever the user has defined, but in this case i would like it to start with my website...

2) How to remove the Scroll bar ?
Was This Post Helpful? 0
  • +
  • -

#3 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Posted 16 May 2009 - 11:53 AM

If I understand you correctly you are asking: 1. Hide the URL Text Box 2. Navigate to a page instead of Homepage on the load of the Browser 3. Remove the Scroll Bar?

1. Just type: urlTextBox.Visible = false;

2. Just type this in the onload() Event: webBrowser1.Navigate("http://www.example.com");

3. Just set the WebBrowser's ScrollBarsEnabled Property to false or type: webBrowser1.ScrollBarsEnabled = false;

Hope this helps

This post has been edited by gbertoli3: 16 May 2009 - 11:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 tuyen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-August 09

Posted 10 August 2009 - 08:13 AM

Dear !
I am trying implement "highlight" method to above Web Browser. I desire to add a button that when it is clicked, selected text on Browser will will be highlighted. But i don't know how to do. Could some one help me :) !

Thank you very much !
Was This Post Helpful? 0
  • +
  • -

#5 AGRAC393  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Posted 23 August 2009 - 07:59 PM

Thanks, dude! This is great. I have a question... Is this safe to use? I'm not sure if it has any security...? Like IE or Firefox. But all in all, GREAT job!
Was This Post Helpful? 0
  • +
  • -

#6 Fuingurth  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 118
  • Joined: 13-August 09

Posted 13 September 2009 - 08:01 AM

great tut and i see that it works, however when i run it the page displays that the navigation was cancled....
Was This Post Helpful? 0
  • +
  • -

#7 jlholmes21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-November 09

Posted 10 December 2009 - 01:18 AM

Thanks this really helpful but...

1) How do I add tabs?

and...

2) How do I add a print function


View Postgbertoli3, on 16 May, 2009 - 10:53 AM, said:

If I understand you correctly you are asking: 1. Hide the URL Text Box 2. Navigate to a page instead of Homepage on the load of the Browser 3. Remove the Scroll Bar?

1. Just type: urlTextBox.Visible = false;

2. Just type this in the onload() Event: webBrowser1.Navigate("http://www.example.com");

3. Just set the WebBrowser's ScrollBarsEnabled Property to false or type: webBrowser1.ScrollBarsEnabled = false;

Hope this helps


I dont see the point in getting ride of the scrool bar
Was This Post Helpful? 0
  • +
  • -

#8 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Posted 10 December 2009 - 03:20 PM

1. To use tabs: Tutorial(its VB.NET, but not hard to convert to C#)

2. Print function:webBrowser1.ShowPrintDialog(); or webBrowser1.ShowPrintPreviewDialog();

Quote

I dont see the point in getting ride of the scrool bar

Sometimes people, just want to restrict the user from scolling. Examples include Popup windows, Predefined Window Size(doesn't need to scroll), and any other reason.

If you have any further question(s) about web browsers in general(and not on this tutorial), then you will get more help if you post it in the forums.

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#9 acilim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-December 09

Posted 18 December 2009 - 01:47 PM

i would like to set home button, but with posibility for user(s) to change it (meaning - ability to change home address)?
Was This Post Helpful? 0
  • +
  • -

#10 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Posted 18 December 2009 - 02:11 PM

You can find where the homepage is set in the registry or you can create a Property to save the homepage(which can be changed via an options dialog).
But to navigate home:webBrowser1.Navigate(System.Properties.Default.Homepage);

Just make sure that the System.Properties.Default.Homepage exists(if not then create it) and that it is either a String or a URI type.

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#11 Guest_Jon-Luc Holmes*


Reputation:

Posted 07 February 2010 - 04:59 AM

CODE IS GOOD BUT

1) I WOULD LIKE TO ADD TABS
2) I WOULD LIKE A PRINT BUTTON
Was This Post Helpful? 0

#12 Guest_jlholmes21*


Reputation:

Posted 07 February 2010 - 07:45 AM

View PostFuingurth, on 13 September 2009 - 07:01 AM, said:

great tut and i see that it works, however when i run it the page displays that the navigation was cancled....


Just publish it to your hard drive so it works perfectly
Was This Post Helpful? 0

#13 Guest_vaknor*


Reputation:

Posted 15 February 2010 - 12:01 AM

hey guys, this is awesome, i will get around to doing it soon, but first, does anyone know the code for opening IE's proxy window
Was This Post Helpful? 0

#14 Guest_doc hardi*


Reputation:

Posted 28 March 2010 - 01:43 PM

hallo howe ei can use the file in the zip pls help my
Was This Post Helpful? 0

#15 Bellars  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-December 10

Posted 13 December 2010 - 01:16 PM

How do you make the webbrowser control load a .html when you click it on windows explorer and so when it loads if you click it on windows explorer the webbrowser control loads it!


Thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2