这个示例展示了如何改变报表的 打印预览 窗体中的工具栏按钮和菜单项的可视性。 要这样做,则把报表指派到 ReportPrintTool 实例,并使用 PrintTool.PrintingSystem 的 PrintingSystemBase.SetCommandVisibility 方法。
下面的代码隐藏了 Watermark 工具栏按钮和相应的菜单项,使 DocumentMap 工具栏按钮和菜单项可视,并使 ExportToCsv 和 ExportToTxt 命令在窗口的菜单和工具栏中都可视。 注意,由 PrintingSystemCommand 枚举表示所有命令的列表。
C# | 复制代码 |
---|---|
using System; using System.Windows.Forms; using DevExpress.XtraPrinting; using DevExpress.XtraReports.UI; // ... private void button1_Click(object sender, EventArgs e) { // Create a report instance, assigned to a Print Tool. ReportPrintTool pt = new ReportPrintTool(new XtraReport1()); // Get the Print Tool's printing system. PrintingSystemBase ps = pt.PrintingSystem; // Hide the Watermark toolbar button, and also the Watermark menu item. if (ps.GetCommandVisibility(PrintingSystemCommand.Watermark) != CommandVisibility.None) { ps.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None); } // Show the Document Map toolbar button and menu item. ps.SetCommandVisibility(PrintingSystemCommand.DocumentMap, CommandVisibility.All); // Make the "Export to Csv" and "Export to Txt" commands visible. ps.SetCommandVisibility(new PrintingSystemCommand[] { PrintingSystemCommand.ExportCsv, PrintingSystemCommand.ExportTxt }, CommandVisibility.All); // Show the report's preview. pt.ShowPreview(); } |
Visual Basic | 复制代码 |
---|---|
Imports System Imports System.Windows.Forms Imports DevExpress.XtraPrinting Imports DevExpress.XtraReports.UI ' ... Private Sub button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles button1.Click ' Create a report instance, assigned to a Print Tool. Dim pt As New ReportPrintTool(New XtraReport1()) ' Get the Print Tool's printing system. Dim ps As PrintingSystemBase = pt.PrintingSystem ' Hide the Watermark toolbar button, and also the Watermark menu item. If ps.GetCommandVisibility(PrintingSystemCommand.Watermark) <> CommandVisibility.None Then ps.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None) End If ' Show the Document Map toolbar button and menu item. ps.SetCommandVisibility(PrintingSystemCommand.DocumentMap, CommandVisibility.All) ' Make the "Export to Csv" and "Export to Txt" commands visible. ps.SetCommandVisibility(New PrintingSystemCommand() { PrintingSystemCommand.ExportCsv, _ PrintingSystemCommand.ExportTxt }, CommandVisibility.All) ' Show the report's preview. pt.ShowPreview() End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E105。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |