2

我正在尝试根据页码以编程方式设置活动报告中的边距。

具体来说,第一页需要有较小的边距(以便最上面的带有退货地址的文本框与公司徽标的对齐方式相匹配),之后的每一页都应该有标准的 2.54 厘米边距。

我读过一些帖子,建议检测实际页码可能会出现问题,因此我尝试使用 ReportStart 和 PageStart 处理程序以及一些非常简单的逻辑来设置边距。

在报告的代码隐藏中,我添加了两个处理程序和 bool 值:

 this.ReportStart += UFAnReportStart;
        this.PageStart += UFAnPageStart;
 bool bFirstPage = true;

然后添加两个回调如下:

private void UFAnReportStart(object sender, System.EventArgs eArgs)
    {           
        this.PageSettings.Margins.Top = 0.1965278F;
    }

private void UFAnPageStart(object sender, System.EventArgs eArgs)
    {
        // every page after the first should have standard margins.
        if (!bFirstPage)
        {               
            this.PageSettings.Margins.Top = 2.54F;
        }
        bFirstPage = false;
    }

这似乎对利润没有任何影响。这种方法是完全错误的吗?还是PageSettings对象是报表范围的属性?

欢迎任何有关替代方法的建议。

使用 Activereports3,版本 5.2.1013.2。

谢谢!

4

2 回答 2

4

Programmatically the units are in inches not CM :) The design-time setting only affects what is shown in the designer.

The following worked for me:

public void ActiveReport_ReportStart()
{
    rpt.PageSettings.Margins.Top = 0.05f;
    rpt.PageSettings.Margins.Left = 0.05f;
    rpt.PageSettings.Margins.Right = 0.05f;
    rpt.PageSettings.Margins.Bottom = 0.05f;    
}

public void ActiveReport_PageEnd()
{
    // The first page (page index 0) will inherit the page margins set in ReportStart. 
    // We immediately reset the page margins in the first PageEnd event to ensure subsequent pages get the larger margins.
    if (rpt.Document.Pages.Count == 0)
    {
        rpt.PageSettings.Margins.Top = 1.0f;
        rpt.PageSettings.Margins.Left = 1.0f;
        rpt.PageSettings.Margins.Right = 1.0f;
        rpt.PageSettings.Margins.Bottom = 1.0f;
    }
}

The ActiveReports Support Forums are free, active, and monitored by our support team so they're a great place to ask questions about ActiveReports.

Hope this helps,

Scott Willeke
GrapeCity inc.
于 2010-07-26T18:12:35.400 回答
0

事实证明,您建议的方法确实有效!我们将文档呈现为 PDF 和 RTF。在 Adob​​e Reader 中以 PDF 格式查看时边距正确,但在 Word 2010 中以 RTF 格式查看时不显示;我没有注意到的东西。

啊,浪费时间!:P

当然,这提出了一个问题,为什么在 RTF-in-word 版本中没有显示边距..?

于 2010-07-26T22:46:40.830 回答