代码之家  ›  专栏  ›  技术社区  ›  Sebastian

在xtrareport中以编程方式设置查看器窗体的标题

  •  2
  • Sebastian  · 技术社区  · 16 年前

    有人知道在显示xtrareport文档时如何设置表单查看器的标题吗? 场景如下:

    我配置了一个XtraReport报告,调用ShowPreviewDialog方法显示它,一个查看器窗体打开并显示文档。我需要设置此查看器窗体的标题,但找不到完成此操作的属性或方法。

    事先谢谢。

    6 回复  |  直到 13 年前
        1
  •  2
  •   Kyle Gagnet    16 年前

    我不认为XtraReport对象使用的预览表单是以您可以简单地设置标题的方式公开的。然而,有可能 create your own preview form . 这将使您能够最终控制预览的显示方式。不幸的是,使用这种方法需要您以不同的方式调用预览。您将不再调用MyReport.ShowPreviewDialog()。在该示例中,报表是在表单的加载事件中创建的预览表单的私有成员。但我会在加载前将对现有报表对象的引用传递到表单中,以便您可以重新使用一个打印预览表单。

        2
  •  5
  •   Andrew Burns    16 年前

    编辑: 显然,如果不调用CreateDocument,它有时会工作,而其他时候则不会。所以确保它在那里(它在我的第一个帖子中丢失了)。

    我相信凯尔的回答不正确。似乎你可以访问表单,这是不直观的。正如Pierre所指出的,创建自己的表单是有正当理由的,但是如果使用默认值查找并且只想自定义标题,请尝试:

    using(var rpt = new XtraReport1())
    {
       rpt.PrintingSystem.PrintPreviewFormEx.Text = "My Custom Caption";
       rpt.CreateDocument();
       rpt.ShowPreviewDialog();
    }
    
        3
  •  2
  •   Pierre-Alain Vigeant    16 年前

    在我们的项目中,我们总是 ReportViewer 窗体的目的是显示 XtraReport (或) PrintingSystem )

    查看器由一个普通的xtraform组成,我们将在其上放置一个printribbonController。这将自动创建功能区栏和打印控件。

    然后,我们使用一种将报表绑定到查看器的方法:

    public partial class ReportViewer : DevExpress.XtraEditors.XtraForm
    {
        public ReportViewer()
        {
            InitializeComponent();
        }
    
        // Used when displaying a single report
        public void SetReport(XtraReport report)
        {
            this.printControl.PrintingSystem = report.PrintingSystem;
            report.CreateDocument();
            this.printControl.UpdatePageView();
        }
    
        // Used when displaying merged reports
        public void SetReport(PrintingSystem system)
        {
            this.printControl.PrintingSystem = system;
            this.printControl.UpdatePageView();
        }
    }
    

    因此,显示报告的过程如下:

    ReportViewer viewer = new ReportViewer();
    viewer.SetReport(new EmployeeReport());
    viewer.Show();
    

    这种创建自己的查看器的方法可以帮助您:

    • 按用户管理安全性(例如:普通用户不能更改水印)。
    • 通过删除或添加按钮来更改功能区以满足您的要求。
        4
  •  2
  •   Troy    14 年前

    我想有一篇关于devexpress支持的文章可以帮助你- Unable to change report preview window titlebar caption

    要点:

    XtraReport1 rep = new XtraReport1();
                rep.CreateDocument();
                PrintPreviewFormEx form = new PrintPreviewFormEx();
                form.Text = "test";
                form.PrintingSystem = rep.PrintingSystem;
                form.Show(); 
    
        5
  •  0
  •   Igor Kustov Vipul    13 年前

    你可以使用 ReportPrintTool 解决问题的类:

    var report = new MyXtraReport();
    ReportPrintTool reportPrintTool = new ReportPrintTool(report);
    reportPrintTool.PreviewForm.Text = "Some Text"
    report.ShowPreviewDialog();    
    
        6
  •  0
  •   Chagbert    13 年前

    我发现皮埃尔的回答非常有用——拥有自己的定制报表查看器确实可以帮助您管理访问等。我添加了以下代码:

     PrintingSystemCommand[] commands = {PrintingSystemCommand.DocumentMap,
                                                       PrintingSystemCommand.Open,
                                                       PrintingSystemCommand.Save};
    
     this.printControl1.PrintingSystem.SetCommandVisibility(commands, CommandVisibility.None);
    

    当然,你必须有参考资料:

    using DevExpress.XtraEditors;
    using DevExpress.XtraReports.UI;
    using DevExpress.XtraPrinting;
    

    再次感谢。

    推荐文章