The WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. You can use the WebBrowser control, for example, to provide integrated HTML-based user assistance or Web browsing capabilities in your application. Additionally, you can use the WebBrowser control to add your existing Web-based controls to your Windows Forms client applications.
Important Note: |
|---|
The
WebBrowser control is resource-intensive. Be sure to call the Dispose()()() method when you are finished using the control to ensure that all resources are released in a timely fashion. You must call the Dispose()()() method on the same thread that attached the events, which should always be the message or user-interface (UI) thread.
|
The WebBrowser control cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
The 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 Navigating, Navigated, and DocumentCompleted events to occur at different stages of navigation.
These and other members, such as the Stop and 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 WebBrowser control on your form. For example, you can use the Print method to print the latest version of a Web page without displaying the page to the user.
The WebBrowser control also lets you display content that you create in your application or you retrieve from a database or resource file. Use the DocumentText or 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 Document property, which contains an 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 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 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 ObjectForScripting property.
Note: |
|---|
This class makes security demands at the class level. A
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.
|
Note: |
|---|
The
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.
|
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note:
Full functionality for the WebBrowser in .NET Compact Framework applications requires Windows Mobile version 5.0 software for Pocket PCs and Smartphones. For more information, see How to: Use the WebBrowser Control in the .NET Compact Framework.