以编程方式设置 XtraReport 中查看器表单的标题

发布于 2024-08-04 18:07:12 字数 164 浏览 6 评论 0原文

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

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

提前致谢。

Does anybody know how to set the title to the form viewer when showing an XtraReport document?
The scenario is the following:

I have an XtraReport report configured, I show it calling the ShowPreviewDialog method, a viewer form opens and shows the document. I need to set the title to this viewer form and can't find the property or way to accomplish this.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

别念他 2024-08-11 18:07:13

编辑:显然,如果您不调用 CreateDocument,它有时会起作用,有时则不起作用。所以请确保它在那里(我的第一篇文章中缺少它)。

我相信凯尔的答案是不正确的。看起来您可以访问该表单,只是不直观。正如皮埃尔指出的那样,创建自己的表单是有充分理由的,但如果您发现使用默认表单并且只想自定义标题,请尝试:

using(var rpt = new XtraReport1())
{
   rpt.PrintingSystem.PrintPreviewFormEx.Text = "My Custom Caption";
   rpt.CreateDocument();
   rpt.ShowPreviewDialog();
}

EDIT: Apparently if you do not call CreateDocument it will appear to work sometimes, other times not. So Make sure it is there (it was missing in my first post).

I believe that Kyle's answer is not correct. It appears that you can access the form, it is just not intuitive. As Pierre pointed out, there are valid reasons to create your own form, but if you are find with the default and just want to customize the title then try:

using(var rpt = new XtraReport1())
{
   rpt.PrintingSystem.PrintPreviewFormEx.Text = "My Custom Caption";
   rpt.CreateDocument();
   rpt.ShowPreviewDialog();
}
可是我不能没有你 2024-08-11 18:07:13

在我们的项目中,我们总是最终创建一个 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();

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

  • 按用户管理安全性(例如:普通用户无法更改水印) ,
  • 通过删除或添加按钮来更改功能区以满足您的要求。

In our projects, we always end up creating a ReportViewer form that purpose is to display a XtraReport (or PrintingSystem).

The viewer consist of a normal XtraForm on which we drop a PrintRibbonController. That will automatically create the ribbon bar and the print control.

Then we use a method that bind the report to the viewer:

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();
    }
}

So displaying a report goes like this:

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

This approach of creating your own viewer can help you:

  • Manages security by user (for example: a normal user can't change the watermark),
  • Changes the ribbon by removing or adding button to fit your requirements.
素染倾城色 2024-08-11 18:07:13

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

I don't believe that the preview form used by the XtraReport object is exposed in such a way that you could simply set the title. However, it is possible to create your own preview form. That would give you ultimate control over how your preview is displayed. Unfortunately, using that approach requires you to invoke the preview differently. You would no longer call myReport.ShowPreviewDialog(). In the example, the report is a private member of the preview form that is created in the form's load event. But I would pass a reference to an existing report object into the form before it loads so you can re-use one print preview form.

聽兲甴掵 2024-08-11 18:07:13

我认为有一篇关于 devexpress 支持的文章可能会对您有所帮助 - 无法更改报告预览窗口标题栏标题

其要点:

XtraReport1 rep = new XtraReport1();
            rep.CreateDocument();
            PrintPreviewFormEx form = new PrintPreviewFormEx();
            form.Text = "test";
            form.PrintingSystem = rep.PrintingSystem;
            form.Show(); 

I think there is an article on the devexpress suport that might help you - Unable to change report preview window titlebar caption

The gist of it:

XtraReport1 rep = new XtraReport1();
            rep.CreateDocument();
            PrintPreviewFormEx form = new PrintPreviewFormEx();
            form.Text = "test";
            form.PrintingSystem = rep.PrintingSystem;
            form.Show(); 
转瞬即逝 2024-08-11 18:07:13

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

var report = new MyXtraReport();
ReportPrintTool reportPrintTool = new ReportPrintTool(report);
reportPrintTool.PreviewForm.Text = "Some Text"
report.ShowPreviewDialog();    

You can use ReportPrintTool class for fixing your problem:

var report = new MyXtraReport();
ReportPrintTool reportPrintTool = new ReportPrintTool(report);
reportPrintTool.PreviewForm.Text = "Some Text"
report.ShowPreviewDialog();    
糖粟与秋泊 2024-08-11 18:07: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;

再次感谢。

I have found Pierre's answer very helpful - having your own custom Report Viewer can indeed help you manage access and the like. I have added this code:

 PrintingSystemCommand[] commands = {PrintingSystemCommand.DocumentMap,
                                                   PrintingSystemCommand.Open,
                                                   PrintingSystemCommand.Save};

 this.printControl1.PrintingSystem.SetCommandVisibility(commands, CommandVisibility.None);

Of-course you gotta have the references:

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

Thanks Again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文