下面的示例演示了如何打印 TreeList,或者显示其打印预览。 为了执行此任务,使用了 TreeList.PrintTreeList.ShowPrintPreview 方法。

仅当 XtraPrinting 库可用时,才能打印和预览树状列表。 因此,为了验证是否可以打印树状列表,在打印控件之前检查了 TreeList.IsPrintingAvailable 属性。

下面的插图展示了预览中的树状列表。

C#CopyCode image复制代码
using DevExpress.XtraTreeList;
// ...

private void ShowTreeListPreview(TreeList treeList) {
    // Check whether the TreeList can be previewed.
    if (!treeList.IsPrintingAvailable) {
        MessageBox.Show("The XtraPrinting Library is not found", "Error");
        return;
    }

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

private void PrintTreeList(TreeList treeList) {
    // Check whether the TreeList can be printed.
    if (!treeList.IsPrintingAvailable) {
        MessageBox.Show("The XtraPrinting Library is not found", "Error");
        return;
    }

    // Print.
    treeList.Print();
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraTreeList
' ...

Sub ShowTreeListPreview(ByVal treeList As TreeList)
   ' Check whether the TreeList can be previewed.
   If Not treeList.IsPrintingAvailable Then
      MessageBox.Show("The XtraPrinting Library is not found", "Error")
      Return
   End If

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

Sub PrintTreeList(ByVal treeList As TreeList)
   ' Check whether the TreeList can be printed.
   If Not treeList.IsPrintingAvailable Then
      MessageBox.Show("The XtraPrinting Library is not found", "Error")
      Return
   End If

   ' Print.
   treeList.Print()
End Sub