[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
   [Expand]Product Information
   [Expand]Getting Started
   [Expand]Fundamental Concepts
    [Collapse]Print Preview
      How to: Add a Print Preview to a Windows Forms Application
      How to: Preview, Export and Print a Windows Forms Control
      How to: Preview, Export and Print an XtraReport
      How to: Preview, Export and Print a Remotely Created Document
      How to: Show a Progress Bar during Document Generation
      How to: Execute Commands in the Print Preview
      How to: Change The Visibility of Toolbar Buttons and Menu Items in the Print Preview
      How to: Customize How a Document Is Exported from the Print Preview
      How to: Hide some of the Export Options in the Print Preview
      How to: Change the Measurement System Exposed in the Print Preview
    [Expand]Using Bricks
    [Expand]Using Printing Links
    [Expand]Page Header and Footer
    [Expand]Printing DevExpress Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Preview, Export and Print a Windows Forms Control

This topic demonstrates how you can create a print preview for a document generated based on a Windows Forms control. In this tutorial, a print preview is created to show a GridControl's content. You can use the same techniques to preview the content of any control that implements the IPrintable interface.

To get started with this tutorial, create a Windows Forms Application with a print preview, similar to the one created in the following tutorial: How to: Add a Print Preview to a Windows Forms Application.

This tutorial consists of the following sections.

Expanded Add a Grid Control

  1. Add a new page ("Grid") to the Ribbon toolbar using the Ribbon Control Designer. To learn how to manage ribbon items, see the Ribbon Items Page topic.
  2. To add a grid to the main form, press CTRL+ALT+X to open the Toolbox. Next, drag the GridControl control from the DX.19.2: Data & Analytics category and drop it on the form.

  3. Bind the grid control to data. To learn how to bind the grid control to data sources of different types, see the Examples: Data Binding topic.
  4. To use the Ribbon control's pages to quickly switch between the grid and print preview, handle the RibbonControl.SelectedPageChanged event, and add the following code to the event handler.

Expanded Create a Printing Link

To generate a printable document from document sources of different kinds, the Printing System class provides printing links that are used to provide a printable presentation to a control's data. For general information on this, refer to the Printing Links topic.

To create a printing link for a grid control, do the following.

  1. To add a printing system to the print preview, select the DocumentViewer control and click its smart tag. Next, expand the Document Source property drop-down list, and select the PrintingSystem item in the Standard Sources category.

    This will add a new Printing System to the application and assign it to the DocumentViewer.DocumentSource property of the document viewer.

  2. A printing system hosts links that can print different controls. To print Windows Forms controls that implement the IPrintable interface, add a PrintableComponentLink to the PrintingSystem.Links collection. To do this, select the printing system in the component tray, click its smart tag, and click the ellipsis button for the Links property in the invoked actions list.

    In the invoked Link Collection Editor, click Add and select DevExpress.XtraPrinting.PrintableComponentLink from the drop-down list.

  3. To assign the Grid Control to the created link, select the link in the Members list, and expand the drop-down list for its PrintableComponentLinkBase.Component property. Select Grid Control and click OK, to save the changes and close the dialog.

Expanded Publish the Document

A Windows Forms application with a print preview is now ready. You can change the GridControl layout by applying grouping, filtering or sorting.

To preview the document, click the Print Preview tab on the Ribbon. Use the menu options in this tab to print and/or export the document.

Is this topic helpful?​​​​​​​