0

実行時に表示されるフィールドを追加するActiveReports6.0レポートがあります。これらのフィールドと表示されるデータは、DataGridViewからのものです。

問題は、表示されるフィールドの合計幅が、印刷されるページの幅(A4など)よりも大きくなると、フィールドが次の物理ページに続き、1つのページに部分的に印刷されることです。ページを作成し、新しいページで休憩します。

現在のページに幅を完全に印刷できない場合にフィールドを新しいページに移動できるように、解決策を見つけることができません。

例:

8列のDataGridViewがあり、それぞれの幅は250ピクセルで、合計で2000ピクセルになります。これは、96DPIシステムの場合は約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 に答える