corelibraries-devexpress-dot-xtraprinting-500788bc.md
A visual brick which is displayed in the page header or page footer sections, and contains information specific to the current page.
Namespace : DevExpress.XtraPrinting
Assembly : DevExpress.Printing.v25.2.Core.dll
NuGet Package : DevExpress.Printing.Core
public class PageInfoBrick :
PageInfoTextBrick,
IPageBrick
Public Class PageInfoBrick
Inherits PageInfoTextBrick
Implements IPageBrick
The following members return PageInfoBrick objects:
PageInfoBrick is a visual brick intended to print document-specific information in a report, such as the current date-time, or a page number (among the total number of pages, in roman numerals or simply as a text string).
The type of information to display is defined via the PageInfoTextBrick.PageInfo and PageInfoTextBrick.Format properties.
For additional information on formatting different value types, see the following topic in MSDN : IFormatProvider.
Note
Unlike other brick types, when defining the location of a PageInfoBrick , the Brick.Rect property value determines only the brick’s dimensions, while the actual brick location is defined solely by the PageInfoBrick.Alignment property.
The following example demonstrates how to use bricks of different types to display different kinds of information in a report.
First, drop a simple button onto a form and handle its Click event. In the event handler, create a new PrintingSystem class instance. Then, create a new Link object and add it to the PrintingSystem.Links collection. Subscribe to the LinkBase.CreateDetailArea and LinkBase.CreateMarginalHeaderArea events to customize a document’s detail and marginal header sections, respectively. Finally, create a document and show it in the print preview by calling the Link.ShowPreview method.
In the CreateDetailArea event handler, use the ImageBrick object to display the picture of a fish and the TextBrick object to show text containing species characteristics and its description. The code also adds a CheckBoxBrick to the document and uses a simple Brick to draw borders around specific bricks.
The CreateMarginalHeaderArea event handler uses the PageImageBrick and PageInfoBrick objects to show additional information in the page header. The PageImageBrick displays the DevExpress logo at the top of every page, while two PageInfo bricks display either the current date and time or the page number, depending on the PageInfoTextBrick.PageInfo property value.
For this example, add the “angelfish.png” and “logo.png” image files to the project. You can get the necessary files from the table below.
|
angelfish.png
|
logo.png
| |
|
|
The following image shows the resulting report.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/reporting-printing-library-use-different-brick-types
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
namespace DifferentBrickTypes
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
// Create a new Printing System.
PrintingSystem printingSystem = new PrintingSystem();
// Create a link and add it to the printing system's collection of links.
Link link = new Link();
printingSystem.Links.Add(link);
// Subscribe to the events to customize the detail and marginal page header sections of a document.
link.CreateDetailArea += Link_CreateDetailArea;
link.CreateMarginalHeaderArea += Link_CreateMarginalHeaderArea;
// Create a document and show it in the document preview.
link.ShowPreview();
}
private void Link_CreateDetailArea(object sender, CreateAreaEventArgs e)
{
// Specify required settings for the brick graphics.
BrickGraphics brickGraphics = e.Graph;
BrickStringFormat format = new BrickStringFormat(StringAlignment.Near, StringAlignment.Center);
brickGraphics.StringFormat = format;
brickGraphics.BorderColor = SystemColors.ControlDark;
// Declare bricks.
ImageBrick imageBrick;
TextBrick textBrick;
CheckBoxBrick checkBrick;
Brick brick;
// Declare text strings.
string[] rows = { "Species No:", "Length (cm):", "Category:", "Common Name:", "Species Name:" },
desc = { "90070", "30", "Angelfish", "Blue Angelfish", "Pomacanthus nauarchus" };
string note = "Habitat is around boulders, caves, coral ledges and crevices in shallow waters. " +
"Swims alone or in groups. Its color changes dramatically from juvenile to adult. The mature" +
" adult fish can startle divers by producing a powerful drumming or thumping sound intended " +
"to warn off predators. Edibility is good. Range is the entire Indo-Pacific region.";
// Define the image to display.
Image img = Image.FromFile(@"..\..\angelfish.png");
// Start creation of a non-separable group of bricks.
brickGraphics.BeginUnionRect();
// Display the image.
imageBrick = brickGraphics.DrawImage(img, new RectangleF(0, 0, 250, 150), BorderSide.All, Color.Transparent);
imageBrick.Hint = "Blue Angelfish";
textBrick = brickGraphics.DrawString("1", Color.Blue, new RectangleF(5, 5, 30, 15), BorderSide.All);
textBrick.StringFormat = textBrick.StringFormat.ChangeAlignment(StringAlignment.Center);
// Display a checkbox.
checkBrick = brickGraphics.DrawCheckBox(new RectangleF(5, 145, 10, 10), BorderSide.All, Color.White, true);
// Create a set of bricks, representing a column with species names.
brickGraphics.BackColor = Color.FromArgb(153, 204, 255);
brickGraphics.Font = new Font("Arial", 10, FontStyle.Italic | FontStyle.Bold | FontStyle.Underline);
for (int i = 0; i < 5; i++)
{
// Draw a VisualBrick representing borders for the following TextBrick.
brick = brickGraphics.DrawRect(new RectangleF(256, 32 * i, 120, 32), BorderSide.All,
Color.Transparent, Color.Empty);
// Draw the TextBrick with species names.
textBrick = brickGraphics.DrawString(rows[i], Color.Black, new RectangleF(258, 32 * i + 2, 116, 28),
BorderSide.All);
}
// Create a set of bricks representing a column with the species characteristics.
brickGraphics.Font = new Font("Arial", 11, FontStyle.Bold);
brickGraphics.BackColor = Color.White;
for (int i = 0; i < 5; i++)
{
brick = brickGraphics.DrawRect(new RectangleF(376, 32 * i, brickGraphics.ClientPageSize.Width - 376, 32),
BorderSide.All,
Color.Transparent, brickGraphics.BorderColor);
// Draw a TextBrick with species characteristics.
textBrick = brickGraphics.DrawString(desc[i], Color.Indigo, new RectangleF(378, 32 * i + 2,
brickGraphics.ClientPageSize.Width - 380, 28),
BorderSide.All);
// For text bricks containing numeric data, set text alignment to Far.
if (i < 2) textBrick.StringFormat =
textBrick.StringFormat.ChangeAlignment(StringAlignment.Far);
}
// Drawing the TextBrick with notes.
brickGraphics.Font = new Font("Arial", 8);
brickGraphics.BackColor = Color.Cornsilk;
textBrick = brickGraphics.DrawString(note, Color.Black, new RectangleF(new PointF(0, 160), new
SizeF(brickGraphics.ClientPageSize.Width, 40)), BorderSide.All);
textBrick.StringFormat = textBrick.StringFormat.ChangeLineAlignment(StringAlignment.Near);
textBrick.Hint = note;
// Finish the creation of a non-separable group of bricks.
brickGraphics.EndUnionRect();
}
private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
{
// Specify required settings for the brick graphics.
BrickGraphics brickGraphics = e.Graph;
brickGraphics.BackColor = Color.White;
brickGraphics.Font = new Font("Arial", 8);
// Declare bricks.
PageInfoBrick pageInfoBrick;
PageImageBrick pageImageBrick;
// Declare text strings.
string devexpress = "XtraPrintingSystem by Developer Express Inc.";
// Define the image to display.
Image pageImage = Image.FromFile(@"..\..\logo.png");
// Display the DevExpress text string.
SizeF size = brickGraphics.MeasureString(devexpress);
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.None, devexpress, Color.Black, new RectangleF(new
PointF(343 - (size.Width - pageImage.Width) / 2, pageImage.Height + 3), size), BorderSide.None);
pageInfoBrick.Alignment = BrickAlignment.Center;
// Display the PageImageBrick containing the DevExpress logo.
pageImageBrick = brickGraphics.DrawPageImage(pageImage, new RectangleF(343, 0,
pageImage.Width, pageImage.Height), BorderSide.None, Color.Transparent);
pageImageBrick.Alignment = BrickAlignment.Center;
// Set the rectangle for a page info brick.
RectangleF r = RectangleF.Empty;
r.Height = 20;
// Display the PageInfoBrick containing the current date and time. The date-time information is displayed
// in the left part of the MarginalHeader section using the FullDateTimePattern.
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.DateTime, "{0:F}", Color.Black, r, BorderSide.None);
pageInfoBrick.Alignment = BrickAlignment.Near;
// Display the PageInfoBrick containing the page number among total pages. The page number
// is displayed in the right part of the MarginalHeader section.
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.NumberOfTotal, "Page {0} of {1}", Color.Black, r,
BorderSide.None);
pageInfoBrick.Alignment = BrickAlignment.Far;
}
}
}
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraPrinting
Namespace DifferentBrickTypes
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
' Create a new Printing System.
Dim printingSystem As New PrintingSystem()
' Create a link and add it to the printing system's collection of links.
Dim link As New Link()
printingSystem.Links.Add(link)
' Subscribe to the events to customize the detail and marginal page header sections of a document.
AddHandler link.CreateDetailArea, AddressOf Link_CreateDetailArea
AddHandler link.CreateMarginalHeaderArea, AddressOf Link_CreateMarginalHeaderArea
' Create a document and show it in the document preview.
link.ShowPreview()
End Sub
Private Sub Link_CreateDetailArea(ByVal sender As Object, ByVal e As CreateAreaEventArgs)
' Specify required settings for the brick graphics.
Dim brickGraphics As BrickGraphics = e.Graph
Dim format As New BrickStringFormat(StringAlignment.Near, StringAlignment.Center)
brickGraphics.StringFormat = format
brickGraphics.BorderColor = SystemColors.ControlDark
' Declare bricks.
Dim imageBrick As ImageBrick
Dim textBrick As TextBrick
Dim checkBrick As CheckBoxBrick
Dim brick As Brick
' Declare text strings.
Dim rows() As String = { "Species No:", "Length (cm):", "Category:", "Common Name:", "Species Name:" }, desc() As String = { "90070", "30", "Angelfish", "Blue Angelfish", "Pomacanthus nauarchus" }
Dim note As String = "Habitat is around boulders, caves, coral ledges and crevices in shallow waters. " & "Swims alone or in groups. Its color changes dramatically from juvenile to adult. The mature" & " adult fish can startle divers by producing a powerful drumming or thumping sound intended " & "to warn off predators. Edibility is good. Range is the entire Indo-Pacific region."
' Define the image to display.
Dim img As Image = Image.FromFile("..\..\angelfish.png")
' Start creation of a non-separable group of bricks.
brickGraphics.BeginUnionRect()
' Display the image.
imageBrick = brickGraphics.DrawImage(img, New RectangleF(0, 0, 250, 150), BorderSide.All, Color.Transparent)
imageBrick.Hint = "Blue Angelfish"
textBrick = brickGraphics.DrawString("1", Color.Blue, New RectangleF(5, 5, 30, 15), BorderSide.All)
textBrick.StringFormat = textBrick.StringFormat.ChangeAlignment(StringAlignment.Center)
' Display a checkbox.
checkBrick = brickGraphics.DrawCheckBox(New RectangleF(5, 145, 10, 10), BorderSide.All, Color.White, True)
' Create a set of bricks, representing a column with species names.
brickGraphics.BackColor = Color.FromArgb(153, 204, 255)
brickGraphics.Font = New Font("Arial", 10, FontStyle.Italic Or FontStyle.Bold Or FontStyle.Underline)
For i As Integer = 0 To 4
' Draw a VisualBrick representing borders for the following TextBrick.
brick = brickGraphics.DrawRect(New RectangleF(256, 32 * i, 120, 32), BorderSide.All, Color.Transparent, Color.Empty)
' Draw the TextBrick with species names.
textBrick = brickGraphics.DrawString(rows(i), Color.Black, New RectangleF(258, 32 * i + 2, 116, 28), BorderSide.All)
Next i
' Create a set of bricks representing a column with the species characteristics.
brickGraphics.Font = New Font("Arial", 11, FontStyle.Bold)
brickGraphics.BackColor = Color.White
For i As Integer = 0 To 4
brick = brickGraphics.DrawRect(New RectangleF(376, 32 * i, brickGraphics.ClientPageSize.Width - 376, 32), BorderSide.All, Color.Transparent, brickGraphics.BorderColor)
' Draw a TextBrick with species characteristics.
textBrick = brickGraphics.DrawString(desc(i), Color.Indigo, New RectangleF(378, 32 * i + 2, brickGraphics.ClientPageSize.Width - 380, 28), BorderSide.All)
' For text bricks containing numeric data, set text alignment to Far.
If i < 2 Then
textBrick.StringFormat = textBrick.StringFormat.ChangeAlignment(StringAlignment.Far)
End If
Next i
' Drawing the TextBrick with notes.
brickGraphics.Font = New Font("Arial", 8)
brickGraphics.BackColor = Color.Cornsilk
textBrick = brickGraphics.DrawString(note, Color.Black, New RectangleF(New PointF(0, 160), New SizeF(brickGraphics.ClientPageSize.Width, 40)), BorderSide.All)
textBrick.StringFormat = textBrick.StringFormat.ChangeLineAlignment(StringAlignment.Near)
textBrick.Hint = note
' Finish the creation of a non-separable group of bricks.
brickGraphics.EndUnionRect()
End Sub
Private Sub Link_CreateMarginalHeaderArea(ByVal sender As Object, ByVal e As CreateAreaEventArgs)
' Specify required settings for the brick graphics.
Dim brickGraphics As BrickGraphics = e.Graph
brickGraphics.BackColor = Color.White
brickGraphics.Font = New Font("Arial", 8)
' Declare bricks.
Dim pageInfoBrick As PageInfoBrick
Dim pageImageBrick As PageImageBrick
' Declare text strings.
Dim devexpress As String = "XtraPrintingSystem by Developer Express Inc."
' Define the image to display.
Dim pageImage As Image = Image.FromFile("..\..\logo.png")
' Display the DevExpress text string.
Dim size_Renamed As SizeF = brickGraphics.MeasureString(devexpress)
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.None, devexpress, Color.Black, New RectangleF(New PointF(343 - (size_Renamed.Width - pageImage.Width) \ 2, pageImage.Height + 3), size_Renamed), BorderSide.None)
pageInfoBrick.Alignment = BrickAlignment.Center
' Display the PageImageBrick containing the DevExpress logo.
pageImageBrick = brickGraphics.DrawPageImage(pageImage, New RectangleF(343, 0, pageImage.Width, pageImage.Height), BorderSide.None, Color.Transparent)
pageImageBrick.Alignment = BrickAlignment.Center
' Set the rectangle for a page info brick.
Dim r As RectangleF = RectangleF.Empty
r.Height = 20
' Display the PageInfoBrick containing date-time information. Date-time information is displayed
' in the left part of the MarginalHeader section using the FullDateTimePattern.
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.DateTime, "{0:F}", Color.Black, r, BorderSide.None)
pageInfoBrick.Alignment = BrickAlignment.Near
' Display the PageInfoBrick containing the page number among total pages. The page number
' is displayed in the right part of the MarginalHeader section.
pageInfoBrick = brickGraphics.DrawPageInfo(PageInfo.NumberOfTotal, "Page {0} of {1}", Color.Black, r, BorderSide.None)
pageInfoBrick.Alignment = BrickAlignment.Far
End Sub
End Class
End Namespace
IXtraSupportDeserializeCollectionItem
Object DevExpress.Printing.Utils.DocumentStoring.StorableObjectBase BrickBase Brick VisualBrick TextBrickBase TextBrick PageInfoTextBrickBase PageInfoTextBrick PageInfoBrick
See Also