Skip to main content

How to: Unite Bricks into a Non-Separable Group

  • 3 minutes to read

This topic describes how you can prevent a group of bricks from being moved away from each other when the page layout changes.

The XtraPrinting Library allows you to modify page margins while previewing a report. You drag the appropriate margin with your mouse, and the report bricks are rearranged automatically. The only problem is that margin changes may impact the report’s layout. For example, non-separable items may be split by page breaks during repagination.

To solve the problem, you can create special groups which can be split apart only if there is no room for the entire group on the page. To accomplish this, call the BrickGraphics.BeginUnionRect method before creating or adding bricks. The BrickGraphics.EndUnionRect method stops the creation of non-separable group.

The following code demonstrates how to create a non-separable group of bricks using the BeginUnionRect and the EndUnionRect methods. The result is shown in the picture below.

Note

These bricks are kept together if the page size allows this; otherwise the group is split as usual.

BeginEndUnionRect

using DevExpress.XtraPrinting;
// ...

    BrickGraphics brickGraph = printingSystem1.Graph;
    int top = 0;

    // Start the report generation.
    printingSystem1.Begin();

    // Specify a page area.
    brickGraph.Modifier = BrickModifier.Detail;
    // Start drawing a brick group.
    brickGraph.BeginUnionRect();

    // Specify formatting.
    brickGraph.StringFormat = new BrickStringFormat(StringAlignment.Center, 
        StringAlignment.Center);
    brickGraph.BackColor = Color.Khaki;
    brickGraph.BorderColor = Color.MidnightBlue;
    brickGraph.Font = new Font("Tahoma", 14, FontStyle.Bold | FontStyle.Italic);

    // Draw bricks.
    brickGraph.DrawString("DevExpress", Color.MidnightBlue,
        new RectangleF(0, 0, 150, 50), BorderSide.All);
    brickGraph.DrawString("100% Native", Color.MidnightBlue,
        new RectangleF(0, top += 50, 150, 50), BorderSide.All);
    brickGraph.DrawString(".NET Tecnologies", Color.MidnightBlue,
        new RectangleF(0, top += 50, 150, 50), BorderSide.All);

    // Finish drawing a brick group.
    brickGraph.EndUnionRect();

    // Finish the report generation.
    printingSystem1.End();

    // Preview the report.
    printingSystem1.PreviewFormEx.Show();
See Also