System.Windows.Forms.WebBrowser Class

Enables the user to navigate Web pages inside your form.

See Also: WebBrowser Members


[System.ComponentModel.Designer("System.Windows.Forms.Design.WebBrowserDesigner, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
public class WebBrowser : WebBrowserBase


The System.Windows.Forms.WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. You can use the System.Windows.Forms.WebBrowser control, for example, to provide integrated HTML-based user assistance or Web browsing capabilities in your application. Additionally, you can use the System.Windows.Forms.WebBrowser control to add your existing Web-based controls to your Windows Forms client applications.


The System.Windows.Forms.WebBrowser control is resource-intensive. Be sure to call the System.ComponentModel.Component.Dispose method when you are finished using the control to ensure that all resources are released in a timely fashion. You must call the System.ComponentModel.Component.Dispose method on the same thread that attached the events, which should always be the message or user-interface (UI) thread.

The System.Windows.Forms.WebBrowser control cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The System.Windows.Forms.WebBrowser control has several properties, methods, and events related to navigation. The following members let you navigate the control to a specific URL, move backward and forward through the navigation history list, and load the home page and search page of the current user:

If the navigation is unsuccessful, a page indicating the problem is displayed. Navigation with any of these members causes the WebBrowser.Navigating, WebBrowser.Navigated, and WebBrowser.DocumentCompleted events to occur at different stages of navigation.

These and other members, such as the WebBrowser.Stop and WebBrowser.Refresh methods, let you implement user interface controls in your application similar to those in Internet Explorer. Some members are useful even when you do not want to display the System.Windows.Forms.WebBrowser control on your form. For example, you can use the WebBrowser.Print method to print the latest version of a Web page without displaying the page to the user.

The System.Windows.Forms.WebBrowser control also lets you display content that you create in your application or you retrieve from a database or resource file. Use the WebBrowser.DocumentText or WebBrowser.DocumentStream property to get or set the contents of the current document as a string or data stream.

You can also manipulate the contents of a Web page through the WebBrowser.Document property, which contains an System.Windows.Forms.HtmlDocument object that provides managed access to the HTML document object model (DOM) for the current page. This property is useful, when used in combination with the WebBrowser.ObjectForScripting property, to implement two-way communication between your application code and dynamic HTML (DHTML) code in a Web page, letting you combine Web-based controls and Windows Forms controls in a single user interface. You can use the WebBrowser.Document property to call scripting code methods from your application. Your scripting code can access your application through the window.external object, which is a built-in DOM object provided for host access, and which maps to the object that you specify for the WebBrowser.ObjectForScripting property.

The System.Windows.Forms.WebBrowser control is a managed wrapper for the ActiveX tp://, and uses whichever version of the control is installed on the user's computer.


This class makes security demands at the class level. A System.Security.SecurityException is thrown when a derived class or any caller in the call stack does not have full trust permission. For details about security demands, see Link Demands and Inheritance Demands.


The System.Windows.Forms.WebBrowser class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.


Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: