Back to Devexpress

IBasePrintable.CreateArea(String, BrickGraphics) Method

corelibraries-devexpress-dot-xtraprinting-dot-ibaseprintable-dot-createarea-x28-system-dot-string-devexpress-dot-xtraprinting-dot-brickgraphics-x29.md

latest6.1 KB
Original Source

IBasePrintable.CreateArea(String, BrickGraphics) Method

When implemented by a class, creates report elements (bricks) for a specific area.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
void CreateArea(
    string areaName,
    BrickGraphics brickGraphics
)
vb
Sub CreateArea(
    areaName As String,
    brickGraphics As BrickGraphics
)

Parameters

NameTypeDescription
areaNameString

The name of the report area (section) for which elements should be created.

| | brickGraphics | BrickGraphics |

A graphical surface on which report elements will be drawn.

|

Remarks

A description of report generation is provided below. It involves using the IPrintable interface, which is a IBasePrintable descendant:

  1. A user generates a report with the ILink.CreateDocument method.
  2. A link knows about the IBasePrintable control to which it refers, and calls the IBasePrintable.Initialize method.
  3. Next, the CreateArea method is called for each section of the report. Refer to the Document Sections topic, to learn about report section types.

When implemented, the CreateArea method must construct different bricks, based on the section type, and information provided by the control.

The following code implements the CreateArea method for the control. The initialized graph object is of the IBrickGraphics interface type, and will be used in other methods listed below.

csharp
void IBasePrintable.CreateArea(string areaName, IBrickGraphics graph) {
    this.graph = graph;
    if( areaName.Equals("PageFooter") )
        CreatePageFooter();
    else if( areaName.Equals("DetailHeader") )
        CreateDetailHeader();
    else if( areaName.Equals("Detail") )
        CreateDetail();
}
vb
Sub CreateArea(ByVal areaName As String, ByVal graph As IBrickGraphics) _
Implements IBasePrintable.CreateArea
    Me.graph = graph
    If areaName.Equals("PageFooter") Then
        CreatePageFooter()
    ElseIf areaName.Equals("DetailHeader") Then
        CreateDetailHeader()
    ElseIf areaName.Equals("Detail") Then
        CreateDetail()
    End If
End Sub

Different methods are called to create the contents for the PageFooter , DetailHeader , and Detail sections. In the following code, we used only the CreatePageFooter method. The DrawBrick method creates a brick object by its name and sets its properties. The ps object of the IPrintingSystem interface was specified by the IBasePrintable.Initialize method.

csharp
private IBrick DrawBrick(string typeName, object[,] properties, RectangleF rect) {
    IBrick brick = ps.CreateBrick(typeName);
    brick.SetProperties(properties);
    return graph.DrawBrick(brick, rect);
}

private void CreatePageFooter() {
    string format = "Page {0} of {1}";
    DXFont font = new DXFont("Arial", 9);
    graph.DefaultBrickStyle = new BrickStyle(BorderSide.None, 1,
        Color.Black, Color.Transparent, Color.Black, font,
        new BrickStringFormat(StringAlignment.Center, StringAlignment.Center));

    float height = font.Height + 2;

    RectangleF r = new RectangleF(0, 0, 0, height);

    DrawBrick("PageInfoBrick", new object[,] { {"PageInfo",PageInfo.DateTime},
    {"AutoWidth",true}, {"Alignment",BrickAlignment.Near} }, r);
    DrawBrick("PageInfoBrick", new object[,] { {"PageInfo",PageInfo.NumberOfTotal}, 
    {"Format",format}, {"Alignment",BrickAlignment.Far}, {"AutoWidth",true} }, r);
}
vb
Private Function DrawBrick(ByVal typeName As String, ByVal properties As Object(,), ByVal rect _
As RectangleF) As IBrick
    Dim brick As IBrick = ps.CreateBrick(typeName)
    brick.SetProperties(properties)
    Return graph.DrawBrick(brick, rect)
End Function

Private Sub CreatePageFooter()
    Dim format As String = "Page {0} of {1}"
    Dim font As DXFont = New DXFont("Arial", 9)

    graph.DefaultBrickStyle = New BrickStyle(BorderSide.None, 1, _
        Color.Black, Color.Transparent, Color.Black, font, _
        New BrickStringFormat(StringAlignment.Center, StringAlignment.Center))

    Dim height As Single = font.Height + 2

    Dim r As RectangleF = New RectangleF(0, 0, 0, height)
    DrawBrick("PageInfoBrick", New Object(,) {{"PageInfo", PageInfo.DateTime}, _
        {"AutoWidth", True}, {"Alignment", BrickAlignment.Near}}, r)
    DrawBrick("PageInfoBrick", New Object(,) {{"PageInfo", PageInfo.NumberOfTotal}, _
        {"Format", format}, {"Alignment", BrickAlignment.Far}, {"AutoWidth", True}}, r)

End Sub

See Also

IBasePrintable Interface

IBasePrintable Members

DevExpress.XtraPrinting Namespace