0

我有一个 ActiveReports 6.0 报告,我正在向其中添加要在运行时显示的字段。这些字段和要显示的数据来自 DataGridView。

问题是,当要显示的字段的总宽度高于要打印的页面的宽度时,例如 A4,然后字段继续在下一个物理页面上,并且碰巧它们被部分打印在一个页面并在新页面上休息。

我找不到任何解决方案,以便如果无法在当前页面上完全打印宽度,我可以将字段移动到新页面。

例子:

有一个 8 列的 DataGridView,每列的宽度为 250 像素,总计 2000 像素,对于 96 DPI 系统来说约为 21 英寸。A4 纸的宽度约为 8.25 英寸。

左边
距:0.25 英寸
右边:0.25 英寸
顶部:0.69 英寸
底部:0.69 英寸

最初的 3 列打印在第 1 页上。第 4 列部分打印在第 1 页上,部分打印在第 2 页上。
我希望第 4 列不能完全打印在第 1 页上,然后将其移到第 2 页,它将完全打印在第 2 页上

提前致谢

4

1 回答 1

1

水平分页确实很棘手。在您的情况下,我想出了以下功能来处理它:

/// <summary>
/// Horizontally page breaks a control.
/// </summary>
/// <param name="requestedLeft">The requested left position of the control.</param>
/// <param name="controlWidth">The width of the control.</param>
/// <param name="paperWidth">The width of the target paper</param>
/// <param name="leftMargin">The width of the paper's left margin.</param>
/// <param name="rightMargin">The width of the paper's right margin.</param>
/// <returns>The new left position for the control. Will be requestedLeft or greater than requestedLeft.</returns>
public static float HorizontallyPageBreak(float requestedLeft, float controlWidth, float paperWidth, float leftMargin, float rightMargin)
{
    var printArea = paperWidth - (leftMargin + rightMargin);
    var requestedPageNum = (int) (requestedLeft/paperWidth);
    // remove the margins so we can determine the correct target page
    var left = (requestedLeft - ((leftMargin + rightMargin) * requestedPageNum));
    var pageNum = (int)( left / printArea);
    var leftOnPage = left % printArea;
    if (leftOnPage + controlWidth > printArea)
    {   // move it to the next page
        left += printArea - leftOnPage;
        left += rightMargin + leftMargin;
    }
    // add in all the prior page's margins
    left += (leftMargin + rightMargin) * pageNum;
    return left;
}

下面是在 ActiveReports 中使用上述函数的简单示例:

NewActiveReport1 rpt = new NewActiveReport1();
float controlWidth = 0.53f;
float nextControlLeft = 0f;

for (int controlCount = 0; controlCount < 1000; controlCount++)
{
    var oldLeft = nextControlLeft;
    controlWidth += 0.21f;

    nextControlLeft = HorizontallyPageBreak(nextControlLeft, controlWidth, rpt.PageSettings.PaperWidth, rpt.PageSettings.Margins.Left, rpt.PageSettings.Margins.Right);
    var txt = new DataDynamics.ActiveReports.TextBox();
    txt.Text = "Column " + controlCount;
    txt.Top = 0;
    txt.Border.Color = Color.Black;
    txt.Border.Style = BorderLineStyle.Solid;
    txt.Left = nextControlLeft;
    txt.Width = controlWidth;
    rpt.Sections["detail"].Controls.Add(txt);
    nextControlLeft += controlWidth;
    rpt.PrintWidth = Math.Max(rpt.PrintWidth, nextControlLeft + controlWidth);
}
this.viewer1.Document = rpt.Document;
rpt.Run(true);
于 2012-02-03T08:54:10.987 回答