Back to Devexpress

How to: Print a LayoutControl and show its print preview

windowsforms-3231-controls-and-libraries-form-layout-managers-layout-and-data-layout-controls-examples-how-to-print-a-layoutcontrol-and-show-its-print-preview.md

latest1.8 KB
Original Source

How to: Print a LayoutControl and show its print preview

  • Nov 13, 2018

The following example demonstrates how to print a LayoutControl and show its Print Preivew. The LayoutControl.Print and LayoutControl.ShowPrintPreview methods are called respectively.

csharp
using DevExpress.XtraLayout;
// ...

private void ShowLayoutControlPreview(LayoutControl layout) {
    // Check whether the LayoutControl can be previewed.
    if (!layout.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Open the Preview window.
    layout.ShowPrintPreview();
}

private void PrintLayoutControl(LayoutControl layout) {
    // Check whether the LayoutControl can be printed.
    if (!layout.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Print.
    layout.Print();
}
vb
Imports DevExpress.XtraLayout
' ...

Sub ShowLayoutControlPreview(ByVal layout As LayoutControl)
   ' Check whether the LayoutControl can be previewed.
   If Not layout.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error")
      Return
   End If

   ' Opens the Preview window.
   layout.ShowPrintPreview()
End Sub

Sub PrintLayoutControl(ByVal layout As LayoutControl
   ' Check whether the LayoutControl can be printed.
   If Not layout.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error")
      Return
   End If

   ' Print.
   layout.Print()
End Sub