Example E91
Visible to All Users

Reporting for WinForms - How to Create a Custom Brick

This example demonstrates how to inherit from existing Brick classes to create custom bricks.

The HyperLinkBrick brick inherits from the TextBrick class.

HyperlinkBrick

The EllipseBrick brick inherits from the Brick class and requires a DevExpress.XtraPrinting.BrickExporters.BrickExporter descendant that implements a method to draw a brick.

EllipseBrick

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
#region usings using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using DevExpress.XtraPrinting; #endregion using MyBrick; namespace CustomBricks { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { HyperLinkBrick hyperBrick = new HyperLinkBrick("http://www.devexpress.com", "Developer Express Inc."); printingSystem1.Begin(); // 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)); printingSystem1.End(); printingSystem1.PreviewFormEx.Show(); } private void button2_Click(object sender, EventArgs e) { #region UsingEllipseBrick Brick brick = new EllipseBrick(Color.LightGreen, Color.Blue); printingSystem1.Begin(); IBrickGraphics graph = printingSystem1.Graph; // Specify the page area to draw a brick. printingSystem1.Graph.Modifier = BrickModifier.Detail; // Add the brick with specified dimensions to the document. graph.DrawBrick(brick, new RectangleF(0, 0, 150, 100)); printingSystem1.End(); printingSystem1.PreviewFormEx.Show(); #endregion } } }
MyBrick.cs(vb)
C#
#region usings using System.Collections; using System.Drawing; using System.Drawing.Drawing2D; using DevExpress.Drawing; using DevExpress.XtraPrinting; using DevExpress.XtraPrinting.BrickExporters; #endregion namespace MyBrick { #region HyperLinkBrick public class HyperLinkBrick : TextBrick { public HyperLinkBrick(string url) : this(url, url) { } 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.OnSetPrintingSystem(cacheStyle); base.ForeColor = Color.Blue; base.Sides = BorderSide.None; this.Font = base.Font; } } #endregion #region EllipseBrick [BrickExporter(typeof(EllipseBrickExporter))] public class EllipseBrick : Brick { // Set gradient colors for inner and outer ellipse regions. public Color InnerColor = Color.Transparent; public Color OuterColor = Color.Peru; public EllipseBrick() { } public EllipseBrick(Color InnerColor, Color OuterColor) { this.InnerColor = InnerColor; this.OuterColor = OuterColor; } } public class EllipseBrickExporter : BrickExporter { EllipseBrick EllipseBrick { get { return (EllipseBrick)Brick; } } // Fills an ellipse with a linear color gradient. public override void Draw(IGraphics gr, RectangleF rect) { using(DXLinearGradientBrush brush = new DXLinearGradientBrush(rect, EllipseBrick.OuterColor, EllipseBrick.InnerColor)) { DXColorBlend colorBlend = new DXColorBlend(); colorBlend.Positions = new float[] { 0.0f, 0.5f, 1.0f }; colorBlend.Colors = new Color[] { EllipseBrick.OuterColor, EllipseBrick.InnerColor, EllipseBrick.OuterColor }; brush.InterpolationColors = colorBlend; gr.FillEllipse(brush, rect); } } } #endregion }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.