windowsforms-devexpress-dot-xtraprinting-dot-link-27dbf5ab.md
Invokes the Print Preview Form which shows the print preview of the document for this link.
Namespace : DevExpress.XtraPrinting
Assembly : DevExpress.XtraPrinting.v25.2.dll
NuGet Package : DevExpress.Win.Printing
public virtual void ShowPreview()
Public Overridable Sub ShowPreview
Use the ShowPreview method to invoke the PrintPreviewFormEx form and show the print preview of the document created for this link. Note that if the link’s document hasn’t been created (the Link.CreateDocument method hasn’t been called for it), then calling the ShowPreview will create it first. Consequently, if a document was created prior to calling the ShowPreview method, and nothing was changed that may force its re-creation, the ShowPreview method doesn’t re-create it, so you need to manually call the Link.CreateDocument method, if required.
The image below displays the standard Print Preview form.
The following code demonstrates how to create a PrintableComponentLink, add it to the PrintingSystem.Links collection, adjust its printing settings, and use it to print an existing GridControl. Use the grid’s OptionsPrint property to customize its printing settings.
using DevExpress.XtraPrinting;
using DevExpress.XtraGrid.Views.Grid;
// ...
// Create printing components.
PrintingSystem printingSystem1 = new PrintingSystem();
PrintableComponentLink printableComponentLink1 = new PrintableComponentLink();
// ...
private void Form1_Load(object sender, EventArgs e) {
// Add the link to the printing system's collection of links.
printingSystem1.Links.AddRange(new object[] { printableComponentLink1 });
// Assign a control to be printed by this link.
printableComponentLink1.Component = gridControl1;
// Assign the printing system to the document viewer.
documentViewer1.PrintingSystem = printingSystem1;
}
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraGrid.Views.Grid
' ...
' Create printing components.
Private printingSystem1 As PrintingSystem = New PrintingSystem()
Private printableComponentLink1 As PrintableComponentLink = New PrintableComponentLink()
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Add the link to the printing system's collection of links.
printingSystem1.Links.AddRange(New Object() { printableComponentLink1 })
' Assign a control to be printed by this link.
printableComponentLink1.Component = gridControl1
' Assign the printing system to the document viewer.
documentViewer1.PrintingSystem = printingSystem1
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-printing-library-get-started/CS/Form1.cs#L17
Lesson1 lesson = new Lesson1(printingSystem1);
lesson.ShowPreview();
}
reporting-printing-library-use-different-brick-types/CS/DifferentBrickTypes/Form1.cs#L29
// Create a document and show it in the document preview.
link.ShowPreview();
}
reporting-winforms-merge-reports-runtime/CS/reportMerging/Form1.cs#L47
public void ShowPreview() {
link.ShowPreview();
}
reporting-printing-library-get-started/VB/Form1.vb#L20
Dim lesson As New Lesson1(printingSystem1)
lesson.ShowPreview()
End Sub
reporting-printing-library-use-different-brick-types/VB/DifferentBrickTypes/Form1.vb#L27
' Create a document and show it in the document preview.
link.ShowPreview()
End Sub
reporting-winforms-merge-reports-runtime/VB/reportMerging/Form1.vb#L58
Public Sub ShowPreview()
Me.link.ShowPreview()
End Sub
See Also