Back to Devexpress

PrintTool.ShowPreviewDialog() Method

windowsforms-devexpress-dot-xtraprinting-dot-printtool-453ce451.md

latest9.0 KB
Original Source

PrintTool.ShowPreviewDialog() Method

Invokes the standard Print Preview dialog 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 ShowPreviewDialog()
vb
Public Sub ShowPreviewDialog

Remarks

Use the ShowPreviewDialog method to invoke the Print Preview dialog showing a report document.

The ShowPreviewDialog method internally calls the XtraReport.CreateDocument method if a report document has not yet been created.

If the document has already been created when you call the ShowPreviewDialog 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 ShowPreviewDialog 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 ShowPreviewDialog() 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-salary-reports/CS/SalaryReports - Step 03/MainForm.cs#L25

csharp
ReportPrintTool printTool = new ReportPrintTool(empReport);
    printTool.ShowPreviewDialog();
}

winforms-reporting-create-report-bound-to-xpobjectsource/CS/Form1.cs#L66

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

reporting-winforms-create-table-at-runtime/CS/Form1.cs#L22

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

reporting-winforms-dynamic-size-image-on-page-settings/CS/WindowsFormsApplication1/Form1.cs#L19

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

reporting-winforms-use-a-custom-function-in-query-expression/CS/SelectQueryWindowsFormsApplication/Form1.cs#L60

csharp
ReportPrintTool pt = new ReportPrintTool(report);
    pt.ShowPreviewDialog();
}

reporting-winforms-salary-reports/VB/SalaryReports - Step 03/MainForm.vb#L19

vb
Dim printTool As ReportPrintTool = New ReportPrintTool(empReport)
    printTool.ShowPreviewDialog()
End Sub

winforms-reporting-create-report-bound-to-xpobjectsource/VB/Form1.vb#L65

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

reporting-winforms-create-table-at-runtime/VB/Form1.vb#L22

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

reporting-winforms-dynamic-size-image-on-page-settings/VB/WindowsFormsApplication1/Form1.vb#L21

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

reporting-winforms-use-a-custom-function-in-query-expression/VB/SelectQueryWindowsFormsApplication/Form1.vb#L57

vb
Dim pt As New ReportPrintTool(report)
    pt.ShowPreviewDialog()
End Sub

See Also

Document Viewer

Print Preview with a Standard Toolbar

ShowRibbonPreviewDialog

PrintTool Class

PrintTool Members

DevExpress.XtraPrinting Namespace