这个示例展示了如何在报表的预览期间执行打印系统命令。 这可能是必要的,例如,要模拟由最终用户执行的单击特定工具栏按钮、或选择特定菜单项的特定操作。 要这样做,则把报表指派到 ReportPrintTool 实例,并使用 PrintTool.PrintingSystem 的 PrintingSystemBase.ExecCommand 方法。
下面的代码阐明了如何改变报表预览的缩放倍数,从而适合整个页面 (通过 ViewWholePage 命令),以及如何调用并隐藏被用于滚动报表页面的 手形 工具。 注意,在本例中,一些命令被调用而没有任何参数,其他命令则需要通过 ExecCommand 方法的重载版本来传递参数。
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; // Show a report's Print Preview. pt.ShowPreview(); // Zoom the print preview, so that it fits the entire page. ps.ExecCommand(PrintingSystemCommand.ViewWholePage); // Invoke the Hand tool. ps.ExecCommand(PrintingSystemCommand.HandTool, new object[] { true }); // Hide the Hand tool. ps.ExecCommand(PrintingSystemCommand.HandTool, new object[] { false }); } |
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 ' Show a report's Print Preview. pt.ShowPreview() ' Zoom the print preview, so that it fits the entire page. ps.ExecCommand(PrintingSystemCommand.ViewWholePage) ' Invoke the Hand tool. ps.ExecCommand(PrintingSystemCommand.HandTool, New Object() { True }) ' Hide the Hand tool. ps.ExecCommand(PrintingSystemCommand.HandTool, New Object() { False }) End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E2304。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |