Share via


WebBrowser Control Overview

The WebBrowser control provides a managed wrapper for the WebBrowser ActiveX control. The managed wrapper lets you display Web pages in your Windows Forms client applications. You can use the WebBrowser control to duplicate Internet Explorer Web browsing functionality in your application or you can disable default Internet Explorer functionality and use the control as a simple HTML document viewer. You can also use the control to add DHTML-based user interface elements to your form and hide the fact that they are hosted in the WebBrowser control. This approach lets you seamlessly combine Web controls with Windows Forms controls in a single application.

Frequently Used Properties, Methods, and Events

The WebBrowser control has several properties, methods, and events that you can use to implement controls found in Internet Explorer. For example, you can use the Navigate method to implement an address bar, and the GoBack, GoForward, Stop, and Refresh methods to implement navigation buttons on a toolbar. You can handle the Navigated event to update the address bar with the value of the Url property and the title bar with the value of the DocumentTitle property.

If you want to generate your own page content within your application, you can set the DocumentText property. If you are familiar with the HTML document object model (DOM), you can also manipulate the contents of the current Web page through the Document property. With this property, you can store and modify documents in memory instead of navigating among files.

The Document property also lets you call methods implemented in Web page scripting code from your client application code. To access your client application code from your scripting code, set the ObjectForScripting property. The object that you specify can be accessed by your script code as the window.external object.

Name Description

Document property

Gets an object that provides managed access to the HTML document object model (DOM) of the current Web page.

DocumentCompleted event

Occurs when a Web page finishes loading.

DocumentText property

Gets or sets the HTML content of the current Web page.

DocumentTitle property

Gets the title of the current Web page.

GoBack method

Navigates to the previous page in history.

GoForward method

Navigates to the next page in history.

Navigate method

Navigates to the specified URL.

Navigating event

Occurs before navigation begins, enabling the action to be canceled.

ObjectForScripting property

Gets or sets an object that Web page scripting code can use to communicate with your application.

Print method

Prints the current Web page.

Refresh method

Reloads the current Web page.

Stop method

Halts the current navigation and stops dynamic page elements such as sounds and animation.

Url property

Gets or sets the URL of the current Web page. Setting this property navigates the control to the new URL.

See Also

Tasks

How to: Navigate to a URL with the WebBrowser Control
How to: Print with a WebBrowser Control
How to: Add Web Browser Capabilities to a Windows Forms Application
How to: Create an HTML Document Viewer in a Windows Forms Application
How to: Implement Two-Way Communication Between DHTML Code and Client Application Code

Reference

WebBrowser
WebBrowserDocumentCompletedEventArgs
WebBrowserDocumentCompletedEventHandler
WebBrowserEncryptionLevel
WebBrowserNavigatedEventArgs
WebBrowserNavigatedEventHandler
WebBrowserNavigatingEventArgs
WebBrowserNavigatingEventHandler
WebBrowserProgressChangedEventArgs
WebBrowserReadyState
WebBrowserRefreshOption

Concepts

WebBrowser Security