Skip to main content

How to: Add a Print Preview to a Windows Forms Application

  • 2 minutes to read

This document describes the steps required to add print preview to a Windows Forms Application to display printable documents from different sources.

Follow these steps to create a print preview:

  1. Run Visual Studio and create a new Windows Forms Application.

  2. To add a print preview to your application, switch to the application’s main form in Visual Studio, and press CTRL+ALT+X to open the Toolbox. Drag the DocumentViewer control from the DX.24.1: Reporting category and drop it onto the form.

    HowTo - ShowPreviewOnForm2.png

  3. Click the control’s smart tag and select a toolbar that matches your application’s user interface style. This tutorial uses the Ribbon toolbar.

    document-viewer-create-ribbon-toolbar

  4. The Document Viewer uses a separate asynchronous task to create a document for preview. Asynchronous document creation does not lock other tasks performed in the application. For instance, the user interface remains responsive. To disable this behavior, set the Document Viewer’s UseAsyncDocumentCreation property to False.

    image

  5. To assign a document source to the Document Viewer, click its smart tag again and select an item from the DocumentViewer.DocumentSource property’s drop-down list.

    document-viewer-select-document-source-standard-printing-system

    To learn how to assign different document sources, refer to the following topics:

  6. Optional. Enable the DirectX Hardware Acceleration. Refer to the viewer’s UseDirectXPaint property description for more information.

The following image illustrates a Document Viewer with no document source assigned to it.

document-viewer-ribbon-empty-document-result

See Also