Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 2.68 KB

how-to-create-an-html-document-viewer-in-a-windows-forms-application.md

File metadata and controls

47 lines (35 loc) · 2.68 KB
title titleSuffix ms.date dev_langs helpviewer_keywords ms.assetid description
Create an HTML Document Viewer in a Windows Forms app
03/30/2017
csharp
vb
WebBrowser control [Windows Forms], creating an HTML document viewer
document viewers
Windows Forms, creating document viewers
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.

How to: Create an HTML Document Viewer in a Windows Forms Application

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.

To create an HTML document viewer

  1. 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]

  2. 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]

Compiling the Code

This example requires:

  • A xref:System.Windows.Forms.WebBrowser control named webBrowser1.

  • References to the System and System.Windows.Forms assemblies.

See also