Configure a WebBrowser Control

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Configure a WebBrowser control


Contents


The WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. For example; rather than rewrite a game that has been written in Javascript, host the web page within a browser to run it locally on a machine.

Image:526-114.jpg


Inheritance hierarchy

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.WebBrowserBase
          System.Windows.Forms.WebBrowser


Useful properties

  • AllowNavigation - Indicates whether the control can navigate to another page after its initial page has been loaded.
  • AllowWebBrowserDrop - Indicates whether the WebBrowser control navigates to documents that are dropped onto it.
  • CanGoBack - Indicates whether a previous page in navigation history is available, which allows the GoBack method to succeed.
  • CanGoForward - Indicates whether a subsequent page in navigation history is available, which allows the GoForward method to succeed.
  • Document - Gets an HtmlDocument representing the Web page currently displayed in the WebBrowser control.
  • DocumentStream - Gets or sets a stream containing the contents of the Web page displayed in the WebBrowser control.
  • DocumentText - Determines the HTML contents of the page displayed in the WebBrowser control.
  • DocumentTitle - Gets the title of the document currently displayed in the WebBrowser control.
  • DocumentType - Gets the type of the document currently displayed in the WebBrowser control.
  • EncryptionLevel - Indicates the encryption method used by the document currently displayed in the WebBrowser control.
  • IsBusy - Indicates whether the WebBrowser control is currently loading a new document.
  • IsOffline - Indicates whether the WebBrowser control is in offline mode.
  • IsWebBrowserContextMenuEnabled - Indicates whether the shortcut menu of the WebBrowser control is enabled.
  • ObjectForScripting - An object that can be accessed by scripting code that is contained within a Web page displayed in the WebBrowser control.
  • ReadyState - Indicates the current state of the WebBrowser control.
  • ScriptErrorsSuppressed - Indicates whether the WebBrowser displays dialog boxes such as script error messages.
  • ScrollBarsEnabled - Indicates whether scroll bars are displayed in the WebBrowser control.
  • StatusText - Gets the status text of the WebBrowser control.
  • Url - Determines the URL of the current document.
  • Version - Gets the version of Internet Explorer installed.
  • WebBrowserShortcutsEnabled - Indicates whether keyboard shortcuts are enabled within the WebBrowser control.


Useful methods

  • GoBack - Navigates the WebBrowser control to the previous page in the navigation history, if one is available.
  • GoForward - Navigates the WebBrowser control to the next page in the navigation history, if one is available.
  • GoHome - Navigates the WebBrowser control to the home page of the current user.
  • GoSearch - Navigates the WebBrowser control to the default search page of the current user.
  • Navigate - Loads the document at the specified location into the WebBrowser control.
  • Print - Prints the document currently displayed in the WebBrowser control using the current print and page settings.
  • Refresh - Reloads the document currently displayed in the WebBrowser control.
  • ShowPageSetupDialog - Opens the Internet Explorer Page Setup dialog box.
  • ShowPrintDialog - Opens the Internet Explorer Print dialog box without setting header and footer values.
  • ShowPrintPreviewDialog - Opens the Internet Explorer Print Preview dialog box.
  • ShowPropertiesDialog - Opens the Internet Explorer Properties dialog box for the current document.
  • ShowSaveAsDialog - Opens the Internet Explorer Save Web Page dialog box or the Save dialog box of the hosted document if it is not an HTML page.
  • Stop - Cancels any pending navigation and stops any dynamic page elements, such as background sounds and animations.


Navigating

The following code example demonstrates how to navigate the WebBrowser control to a specific URL:

this.webBrowser1.Navigate("http://en.csharp-online.net/");

To determine when the new document is fully loaded, handle the DocumentCompleted event. When this event occurs, the contents of the new document can be accessd through the Document, DocumentText, or DocumentStream properties.

To receive notification before navigation begins, handle the Navigating event. This event lets you cancel navigation if certain conditions have not been met, for example, when the user has not completely filled out a form.


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen

Personal tools