This example demonstrates how to inherit from existing Brick classes to create custom bricks.
The HyperLinkBrick brick inherits from the TextBrick class.
The EllipseBrick brick inherits from the Brick class and requires a DevExpress.XtraPrinting.BrickExporters.BrickExporter
descendant that implements a method to draw a brick.
Files to Review
- Form1.cs (VB: Form1.vb)
- MyBrick.cs (VB: MyBrick.vb)
Documentation
More Examples
- How to use a custom BrickExporter
- How to scroll a document in the print preview to a specific page or brick
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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
}
}
}
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
}