Configure a WebBrowser Control
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| 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.
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 theGoBackmethod to succeed.
-
-
CanGoForward- Indicates whether a subsequent page in navigation history is available, which allows theGoForwardmethod to succeed.
-
-
Document- Gets anHtmlDocumentrepresenting the Web page currently displayed in theWebBrowsercontrol.
-
-
DocumentStream- Gets or sets a stream containing the contents of the Web page displayed in theWebBrowsercontrol.
-
-
DocumentText- Determines the HTML contents of the page displayed in theWebBrowsercontrol.
-
-
DocumentTitle- Gets the title of the document currently displayed in theWebBrowsercontrol.
-
-
DocumentType- Gets the type of the document currently displayed in theWebBrowsercontrol.
-
-
EncryptionLevel- Indicates the encryption method used by the document currently displayed in theWebBrowsercontrol.
-
-
IsBusy- Indicates whether theWebBrowsercontrol is currently loading a new document.
-
-
IsOffline- Indicates whether theWebBrowsercontrol is in offline mode.
-
-
IsWebBrowserContextMenuEnabled- Indicates whether the shortcut menu of theWebBrowsercontrol is enabled.
-
-
ObjectForScripting- An object that can be accessed by scripting code that is contained within a Web page displayed in theWebBrowsercontrol.
-
-
ReadyState- Indicates the current state of theWebBrowsercontrol.
-
-
ScriptErrorsSuppressed- Indicates whether theWebBrowserdisplays dialog boxes such as script error messages.
-
-
ScrollBarsEnabled- Indicates whether scroll bars are displayed in theWebBrowsercontrol.
-
-
StatusText- Gets the status text of theWebBrowsercontrol.
-
-
Url- Determines the URL of the current document.
-
-
Version- Gets the version of Internet Explorer installed.
-
-
WebBrowserShortcutsEnabled- Indicates whether keyboard shortcuts are enabled within theWebBrowsercontrol.
-
Useful methods
-
GoBack- Navigates theWebBrowsercontrol to the previous page in the navigation history, if one is available.
-
-
GoForward- Navigates theWebBrowsercontrol to the next page in the navigation history, if one is available.
-
-
GoHome- Navigates theWebBrowsercontrol to the home page of the current user.
-
-
GoSearch- Navigates theWebBrowsercontrol to the default search page of the current user.
-
-
Navigate- Loads the document at the specified location into theWebBrowsercontrol.
-
-
Print- Prints the document currently displayed in theWebBrowsercontrol using the current print and page settings.
-
-
Refresh- Reloads the document currently displayed in theWebBrowsercontrol.
-
-
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
|


