Web Browser In VB.NET

In this article you will learn about what is WebBrowser, its properties and you can use this control.
  • 6450
 

A visual basic WebBrowser control enables the you to navigate web pages inside your form. Navigate method of the WebBrowser control loads the documents into WebBrowser control. It is a managed wrapper around the internet explorer control. WebBrowser is a Dynamic Link Library called shdocvw.dll hosted by internet Explorer. The WebBrowser in trun works through another Dynamic Link Library, the mshtml.dll. This directly interacts with ActiveX controls, script engine and so on. That are embedded in HTML pages. The web browser control takes the URL to display the HTML content. If the source is not a URL but some HTML content it would through up an exception or error.

Inheritance hierarchy for WebBrowser.

  • System.Object 
  • System.MarshalByRefObject 
  • System.ComponentModel.Component 
  • System.Windows.Forms.Control 
  • System.Windows.Forms.WebBrowserBase 
  • System.Windows.WebBrowser
Properties of WebBrowser control.
  • AccessibleRole:- This property will get/set the Accessible Role of the control. 
  • ActiveXInstance:- This property will get the underlying ActiveX WebBrowser control. 
  • AccessibleName:- This property will get/set the name of the control used by accessibility client application. 
  • AllowNavigation:-  Indicate a value Whether the control can navigate on another page after its initial page has been loaded.
How to use WebBrowser control.
  • Open a new Project 
  • Drag one Textbox, Label, Button and a WebBrowser control on form. Your form will display like below.

    WebBrowser1.GIF
     

  • Write the Below code. Then set WebBrowser's anchor and url properties.

        Private
    Sub FrmWebBrowser_Load(ByVal sender As Object, ByVal e As EventArgs)
            Me.Text = "vbdotnetheaven web browser"
            txt_url.Text = "http://www.google.com.pk/"
            wbBrwsr.Navigate("http://www.google.com.pk/")
            Me.WindowState = FormWindowState.Maximized
        End Sub
        Private Sub btn_Go_Click(ByVal sender As Object, ByVal e As EventArgs)
            wbBrwsr.Navigate(txt_url.Text)
        End Sub
Output

WebBrowser3.GIF

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.