Share via


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

You can use the 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 WebBrowser control in this manner, for example, to use it as an HTML e-mail viewer or to provide HTML-formatted help in your application.

To create an HTML document viewer

  1. Set the AllowWebBrowserDrop property to false to prevent the WebBrowser control from opening files dropped onto it.

    webBrowser1.AllowWebBrowserDrop = False
    
    webBrowser1.AllowWebBrowserDrop = false;
    
  2. Set the Url property to the location of the initial file to display.

    webBrowser1.Url = New Uri("https://www.contoso.com/")
    
    webBrowser1.Url = new Uri("https://www.contoso.com/");
    

Compiling the Code

This example requires:

  • A WebBrowser control named webBrowser1.

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

See Also

Tasks

How to: Navigate to a URL with the WebBrowser Control

How to: Print with a WebBrowser Control

Reference

WebBrowser Control Overview

WebBrowser

AllowWebBrowserDrop

Url

Concepts

WebBrowser Security