title | titleSuffix | ms.date | dev_langs | helpviewer_keywords | ms.assetid | description | |||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create an HTML Document Viewer in a Windows Forms app |
03/30/2017 |
|
|
6a6338fe-f7ee-4f5e-9d8f-0465c57e9039 |
Learn how to create an HTML document viewer in a Windows Forms application to display and print HTML documents without a web browser. |
You can use the xref:System.Windows.Forms.WebBrowser control to display and print HTML documents without providing the full functionality of an Internet Web browser. This is useful when you want to take advantage of the formatting capabilities of HTML but do not want your users to load arbitrary Web pages that may contain untrusted Web controls or potentially malicious script code. You might want to restrict the capability of the xref:System.Windows.Forms.WebBrowser control in this manner, for example, to use it as an HTML email viewer or to provide HTML-formatted help in your application.
-
Set the xref:System.Windows.Forms.WebBrowser.AllowWebBrowserDrop%2A property to
false
to prevent the xref:System.Windows.Forms.WebBrowser control from opening files dropped onto it.[!code-csharpWebBrowserMisc#20] [!code-vbWebBrowserMisc#20]
-
Set the xref:System.Windows.Forms.WebBrowser.Url%2A property to the location of the initial file to display.
[!code-csharpWebBrowserMisc#21] [!code-vbWebBrowserMisc#21]
This example requires:
-
A xref:System.Windows.Forms.WebBrowser control named
webBrowser1
. -
References to the
System
andSystem.Windows.Forms
assemblies.
- xref:System.Windows.Forms.WebBrowser
- xref:System.Windows.Forms.WebBrowser.AllowWebBrowserDrop%2A
- xref:System.Windows.Forms.WebBrowser.Url%2A
- WebBrowser Control Overview
- WebBrowser Security
- How to: Navigate to a URL with the WebBrowser Control
- How to: Print with a WebBrowser Control