Back to Devexpress

PrintTool.ShowPreview() Method

windowsforms-devexpress-dot-xtraprinting-dot-printtool-4ed9a409.md

latest8.8 KB
Original Source

PrintTool.ShowPreview() Method

Invokes the standard Print Preview form showing the document that is created from a source (report or link) assigned to the PrintTool.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.XtraPrinting.v25.2.dll

NuGet Package : DevExpress.Win.Printing

Declaration

csharp
public void ShowPreview()
vb
Public Sub ShowPreview

Remarks

Use the ShowPreview method to invoke the Print Preview form showing a report document.

The ShowPreview method internally generates a report document, if it is has not yet been created.

If the document has already been created when you call the ShowPreview method, it will not be re-created. For this reason, if the report has been changed, call the XtraReport.CreateDocument or Link.CreateDocument method prior to calling the ShowPreview method.

After closing the Print Preview form, it is required to explicitly dispose of the document source (report or link) assigned to the PrintTool.

The options of the Print Preview form are available via the PrintTool.PreviewForm property.

Example

In Windows Forms applications, you can show a document’s Print Preview by using the following methods of the ReportPrintTool: PrintTool.ShowPreview and PrintTool.ShowPreviewDialog.

This code will work in your application after you create a new report in it (named XtraReport1 ) and handle the Load event of the application’s main form.

csharp
using System;
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.XtraReports.UI;
// ...

private void Form1_Load(object sender, EventArgs e) {
    XtraReport1 report = new XtraReport1();

    using (ReportPrintTool printTool = new ReportPrintTool(report)) {
        // Invoke the Print Preview form modally, 
        // and load the report document into it.
        printTool.ShowPreviewDialog();

        // Invoke the Print Preview form
        // with the specified look and feel setting.
        printTool.ShowPreviewDialog(UserLookAndFeel.Default);
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraReports.UI
' ...

Private Sub Form1_Load(ByVal sender As Object, _ 
ByVal e As EventArgs) Handles MyBase.Load
    Dim report As New XtraReport1()

    Using printTool As New ReportPrintTool(report)
        ' Invoke the Print Preview form modally, 
        ' and load the report document into it.
        printTool.ShowPreviewDialog()

        ' Invoke the Print Preview form
        ' with the specified look and feel setting.
        printTool.ShowPreviewDialog(UserLookAndFeel.Default)
    End Using
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the ShowPreview() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-appearance-settings/CS/Form1.cs#L15

csharp
ReportPrintTool printTool = new ReportPrintTool(report);
    printTool.ShowPreview();
}

reporting-winforms-add-vertical-brick/CS/T457705/Form1.cs#L22

csharp
ReportPrintTool tool = new ReportPrintTool(report);
    tool.ShowPreview();
}

reporting-winforms-custom-controls-for-editing-report-content-in-print-preview/CS/RegisterCustomFieldEditor/Form1.cs#L74

csharp
ReportPrintTool printTool = new ReportPrintTool(CreateReport());
    printTool.ShowPreview();
}

reporting-winforms-bind-mdb-with-select-query/CS/RuntimeBindingToMdbDatabase/Form1.cs#L79

csharp
ReportPrintTool printTool = new ReportPrintTool(CreateReport());
    printTool.ShowPreview();
}

reporting-winforms-group-at-runtime/CS/DataGrouping/Form1.cs#L70

csharp
ReportPrintTool printTool = new ReportPrintTool(report);
    printTool.ShowPreview();
}

reporting-winforms-appearance-settings/VB/Form1.vb#L18

vb
Dim printTool As ReportPrintTool = New ReportPrintTool(report)
    printTool.ShowPreview()
End Sub

reporting-winforms-add-vertical-brick/VB/T457705/Form1.vb#L24

vb
Dim tool As New ReportPrintTool(report)
    tool.ShowPreview()
End Sub

reporting-winforms-custom-controls-for-editing-report-content-in-print-preview/VB/RegisterCustomFieldEditor/Form1.vb#L62

vb
Dim printTool As ReportPrintTool = New ReportPrintTool(CreateReport())
    printTool.ShowPreview()
End Sub

reporting-winforms-bind-mdb-with-select-query/VB/RuntimeBindingToMdbDatabase/Form1.vb#L71

vb
Dim printTool As New ReportPrintTool(CreateReport())
    printTool.ShowPreview()
End Sub

reporting-winforms-group-at-runtime/VB/DataGrouping/Form1.vb#L65

vb
Dim printTool As ReportPrintTool = New ReportPrintTool(report)
    printTool.ShowPreview()
End Sub

See Also

Document Viewer

Print Preview with a Standard Toolbar

ShowRibbonPreview

PrintTool Class

PrintTool Members

DevExpress.XtraPrinting Namespace