How to: Create a Custom Brick Inherited from a Standard Brick

  • 4 minutes to read

The XtraPrinting Library enables you to create your own custom bricks, and use them in your document. In this topic we introduce one of the approaches to accomplishing this task, which requires deriving a custom brick class from one of the existing brick classes (either the BrickBase class, or its descendants). For information on creating custom bricks by implementing the IBrick interface, refer to the How to: Create a Custom Brick Implementing the IBrick Interface tutorial.

Inheriting a Custom HyperLinkBrick from the TextBrick

Deriving from an existing brick classes allows you quickly create a custom brick and add extra functionality. This example demonstrates how you can create a custom HyperLinkBrick brick. This brick inherits from the TextBrick class, since a TextBrick provides most of the functionality needed for the new brick type.

The purpose of a new brick is to represent hyperlink addresses in a report. This hyperlink is enabled in the report's preview, and the end-user can click it and open a link in the default browser.

The new brick class implements two constructors, used to initialize a HyperLinkBrick class instance. The first constructor has one parameter specifying the url; in this case the displayed hint contains this link. The second one includes two parameters: the url string and the hint text.

The TextBrickBase.ForeColor and TextBrick.Font properties of the base class are hidden and new methods are implemented instead. By default, the Font property sets the text font to be underlined. The ForeColor property sets the text color to blue.

using System;
using System.Text;
using System.Drawing;
using System.Collections.Generic;
using DevExpress.XtraPrinting;
// ...

public class HyperLinkBrick : TextBrick {

    // Constructor, which creates a brick with a single parameter.
    public HyperLinkBrick(string url) : this(url, url) {}

    // Constructor, which creates a brick with a specific url and hint values.
    public HyperLinkBrick(string url, string hint) : base() {
        this.Url = url;
        this.Text = url;
        this.Hint = hint;

    // Specifies the brick text color. 
    public new Color ForeColor {
        get { return Color.Blue; }

    // Specifies the brick text font.
    public new Font Font { 
        get { return base.Font; } 
        set { base.Font = new Font(value.Name, value.Size, 
            value.Style | FontStyle.Underline); }

    // Initializes the brick.
    protected override void OnSetPrintingSystem(bool cacheStyle) {
        base.ForeColor = Color.Blue;
        base.Sides = BorderSide.None;
        this.Font = base.Font; 

Using the HyperLinkBrick

Now you can create and add the HyperLinkBrick to your report as demonstrated below.

// Create a brick.
HyperLinkBrick hyperBrick = new HyperLinkBrick("", 
"Developer Express Inc.");

// Start the report generation.

// Specify the page area to draw a brick.
printingSystem1.Graph.Modifier = BrickModifier.Detail;

// Add the brick with specified dimensions to the document.
printingSystem1.Graph.DrawBrick(hyperBrick, new RectangleF(0, 0, 300, 20));

// Finish the report generation.

// Preview the result.


Note: you can certainly create this brick using the standard brick type, but the HyperLinkBrick class makes this task easier.


A complete sample project is available in the DevExpress Code Examples database at

See Also