下面的示例演示了如何打印 GridControl 或显示它的打印预览。 要执行此操作,应使用 GridControl.Print 或 GridControl.ShowPrintPreview 方法。
注意 |
---|
仅当 XtraPrinting 库可用时,才可以打印和预览 GridControl。 要检查是否可以打印 Grid,可以使用 GridControl.IsPrintingAvailable 属性。 |
在打印 Grid 时,当前的打印设置将被用于呈现 Grid。 注意,可以通过 GridView.OptionsPrint、BandedGridView.OptionsPrint 或 CardView.OptionsPrint 属性访问及修改打印设置。
C# | 复制代码 |
---|---|
using DevExpress.XtraGrid; // ... private void ShowGridPreview(GridControl grid) { // Check whether the GridControl can be previewed. if (!grid.IsPrintingAvailable) { MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error"); return; } // Open the Preview window. grid.ShowPrintPreview(); } private void PrintGrid(GridControl grid) { // Check whether the GridControl can be printed. if (!grid.IsPrintingAvailable) { MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error"); return; } // Print. grid.Print(); } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid ' ... Sub ShowGridPreview(ByVal grid As GridControl) ' Check whether the GridControl can be previewed. If Not grid.IsPrintingAvailable Then MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error") Return End If ' Opens the Preview window. grid.ShowPrintPreview() End Sub Sub PrintGrid(ByVal grid As GridControl) ' Check whether the GridControl can be printed. If Not grid.IsPrintingAvailable Then MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error") Return End If ' Print. grid.Print() End Sub |
下面的插图展示了示例网格控件的预览窗口。