Skip to main content
A newer version of this page is available. .

Create a Custom Print Preview

  • 2 minutes to read

Note

You need a WinForms subscription to use the API described in this tutorial.

The Invoke a Default Print Preview Form tutorial illustrates how to open the Print Preview with the Reporting subscription.

You can implement a custom Print Preview form in your WinForms application. This tutorial demonstrates how to do this using the DocumentViewer control and binding it to a report.

Note

If your WinForms application targets .NET Core/.NET5+, add the DevExpress.Win.Design NuGet package to this application to use the DocumentViewer control.

  1. Switch to the application’s main form in Visual Studio and press CTRL+ALT+X to open the Toolbox. Expand the DX.21.2: Reporting category and drop the DocumentViewer control onto the form.

    winforms-add-document-viewer-control

  2. Click the Document Viewer’s smart tag and select the report in the Document Source drop-down menu to assign a report to the DocumentViewer.DocumentSource property.

    winforms-document-viewer-document-source

    Tip

    The application project should be built so that the reports it includes are available in the Document Source drop-down menu.

  3. Click the Document Viewer’s smart tag and select the Create Ribbon Toolbar or Create Standard Toolbar action to create the required toolbar.

    winforms-document-viewer-create-toolbar

  4. Optional. If you want to preview a large report that might consume a lot of memory, bind the DocumentViewer control to the CachedReportSource component instead. This component stores document pages in a file system or database when the document is generated and thus allows you to avoid issues related to memory consumption.

    Check the Cache Document Source option in the Document Viewer’s smart tag after setting the Document Source property:

    winforms-document-viewer-cached-document-source

    This adds the CachedReportSource component to the form. You can now change the component’s settings. Assign one of the following ready-to-use document storages to the Storage property:

    MemoryDocumentStorage
    Allows you to compactly store a document in memory.
    FileDocumentStorage
    Allows you to store a document as a set of files in the specified directory.
    DbDocumentStorage
    Allows you to store a document in a database.

    winforms-document-viewer-cached-document-source-properties

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

See Also