注意 |
---|
重要说明: .NET Client Profile Framework 不支持此功能。 要在最终用户的机器上使用此功能,则必须安装完整的 .NET Framework。 更多信息,请参阅 Windows 窗体部署 文档中的 关于 .NET Framework 4.0 Client Profile 的重要说明 小节。 |
这个示例展示了如何以程序方式调用 报表向导,这是通过调用有 ReportCommand.NewReportWizard 参数的 XRDesignPanel.ExecCommand 方法完成的。
在报表已经被创建之后,它就被保存为一个临时文件,后面可以重建和预览它。
C# | 复制代码 |
---|---|
using System; using System.Windows.Forms; using DevExpress.XtraReports.UI; using DevExpress.XtraReports.UserDesigner; // ... private void simpleButton1_Click(object sender, EventArgs e) { // The name for a file to save a report. string tempFile = "temp.repx"; // Run the Wizard to create a new report. CreateReport(tempFile); // Preview the previously created report. PreviewReport(tempFile); } private void CreateReport(string fileName) { // Create the End-User Designer form. XRDesignForm form = new XRDesignForm(); // Load a blank report to the End-User Designer. form.OpenReport(new XtraReport()); // Run the Report Wizard. form.ActiveDesignPanel.ExecCommand(ReportCommand.NewReportWizard); // Save the report to the temp file. form.ActiveDesignPanel.Report.SaveLayout(fileName); } private void PreviewReport(string fileName) { // Load the report from the temp file. XtraReport newReport = XtraReport.FromFile(fileName, true); // Show its print preview. newReport.ShowPreview(); } |
Visual Basic | 复制代码 |
---|---|
Imports System Imports System.Windows.Forms Imports DevExpress.XtraReports.UI Imports DevExpress.XtraReports.UserDesigner ' ... Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles simpleButton1.Click ' The name for a file to save a report. Dim tempFile As String = "temp.repx" ' Run the Wizard to create a new report. CreateReport(tempFile) ' Preview the previously created report. PreviewReport(tempFile) End Sub Private Sub CreateReport(ByVal fileName As String) ' Create the End-User Designer form. Dim form As New XRDesignForm() ' Load a blank report to the End-User Designer. form.OpenReport(New XtraReport()) ' Run the Report Wizard. form.ActiveDesignPanel.ExecCommand(ReportCommand.NewReportWizard) ' Save the report to the temp file. form.ActiveDesignPanel.Report.SaveLayout(fileName) End Sub Private Sub PreviewReport(ByVal fileName As String) ' Load the report from the temp file. Dim newReport As XtraReport = XtraReport.FromFile(fileName, True) ' Show its print preview. newReport.ShowPreview() End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E93。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |