【问题标题】:Set alignment of XRPictureBox at runtime在运行时设置 XRPictureBox 的对齐方式
【发布时间】:2013-10-23 05:10:34
【问题描述】:

我想创建一个 XtraReport 模板类,它获取一个报表对象并将其转换为我们的公司设计。首先,我创建了一个 ReportHeaderBand,它为 Logo 获取了一个 XRPictureBox。如何将 XRPictureBox 放在 ReportHeaderBand 的右侧?

这就是我目前正在做的事情:

internal class Kopfbereich: ReportHeaderBand
    {
        /// <summary>
        /// Erstellt ein Objekt für den Kopfbereich eines Reports
        /// </summary>
        public Kopfbereich()
        {
            DruckeLogo();
        }

        private void DruckeLogo()
        {
            XRPictureBox picBox = new XRPictureBox();
            picBox.Visible = true;
            picBox.Sizing = ImageSizeMode.AutoSize;
            picBox.Image = Resources.Brillux_Logo_Reports_ohne_Text;
            this.Controls.Add(picBox);
        }
    }

    //This Method is from other class and should print my report with template
    public XtraReport DruckeMitVorlage(XtraReport report)
    {
        Kopfbereich kopfbereich = new Kopfbereich();
        report.Bands.Add(kopfbereich);
        return report;
    }

我想在运行时创建它以获得动态模板。所以设计师不是一个选择。

我尝试了以下代码行来设置右侧的 XRPictureBox。

picBox.LocationF = new PointF(Report.PageWidth - picBox.WidthF - Report.Margins.Right.Width, 0);

但是徽标在下一页上显示一半。

【问题讨论】:

    标签: c# winforms devexpress xtrareport


    【解决方案1】:

    我建议您将此XRPictureBox 控件添加到report header band 而不是this.Controls。它可以控制图片编辑打印在报表的顶部,而不是打印在其他页面上。..

    检查代码sn-p:

    // Check if the TopMargin band is already present in the report. 
    if(Bands.GetBandByType(typeof(ReportHeaderBand)) == null) {
        // Create a new TopMargin band and add it to the report. 
        ReportHeaderBandtmBand = new ReportHeaderBand();
        Bands.Add(tmBand);
    
        // Create a picture object
        XRPictureBox picBox = new XRPictureBox();
        picBox.Visible = true;
        picBox.Sizing = DevExpress.XtraPrinting.ImageSizeMode.AutoSize;
        picBox.Image = Resources.Logo;
        this.Controls.Add(picBox);
    
        // Add the label to the ReportHeaderBand band. 
        tmBand.Controls.Add(picBox);
    }
    

    您可以使用以下报表对象进行控制:

     // Place the chart onto a report footer
      rep.Bands[BandKind.ReportHeader].Controls.Add(picBox);
    

    参考:
    How to create a report dynamically in the WinForms application

    【讨论】:

    • 我编辑了我的帖子。抱歉不要发布完整的代码。事实上,我和你想的一样。我只是不知道如何在右边框上获取 XRPictureBox(对齐 = 右)。感谢您的快速答复。
    • 尝试将面板添加到报告标题,然后将此图片控件添加到其中。然后尝试在打印事件之前使用以获取放置点。 XRControls 的Dock 属性可能是绝对的。
    • 问题是我无法将点放置。 BeforePrint 事件只给我一个 PrintAction 和一个 Cancel。如何获取 ReportHeaderBand 右侧的位置来为我的 XRPictureEdit 设置它?没有对齐属性:-(
    猜你喜欢
    • 2018-08-05
    • 2012-03-23
    • 2013-04-18
    • 2012-04-28
    • 1970-01-01
    • 2017-08-05
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多