Search
Brush and Pen Classes

MindFusion.Diagramming defines proxy classes to wrap the functionality of standard .NET brushes and pens and expose them as properties of diagram elements. Those classes, located in the MindFusion.Drawing namespace, have the same names as their System.Drawing counterparts. There are five brush classes that inherit the abstract class Brush, namely HatchBrush, LinearGradientBrush, PathGradientBrush, SolidBrush and TextureBrush. There's also a Pen class - proxy for the .NET Pen.

There are two reasons to use proxy classes instead the original GDI classes. First, the GDI resources are limited and would be exhausted by keeping a GDI pen and brush attached all the time to each diagram element; by using proxies the GDI pen and brush are created only at the time of drawing, and immediately disposed after that. Second, the GDI Pen and Brush classes don't support serialization; the proxy-classes implement the required interfaces instead.

Otherwise the proxy classes expose the same properties as their GDI counterparts. You might set default pen and brush properties like this:

C#  Copy Code

diagram.ShapeBrush = new MindFusion.Drawing.LinearGradientBrush(
    Color.Yellow, Color.BurlyWood, 20);

MindFusion.Drawing.Brush penBrush = new MindFusion.Drawing.LinearGradientBrush(
    Color.Bisque, Color.Blue, 0);
diagram.ShapePen = new MindFusion.Drawing.Pen(penBrush);

Visual Basic  Copy Code

Diagram.ShapeBrush = New MindFusion.Drawing.LinearGradientBrush( _
    Color.Yellow, Color.BurlyWood, 20)

Dim penBrush As MindFusion.Drawing.Brush = New MindFusion.Drawing.LinearGradientBrush( _
    Color.Bisque, Color.Blue, 0)
Diagram.ShapePen = New MindFusion.Drawing.Pen(penBrush)

After that piece of code is executed, every new shape node created will have gradient brush and pen.

Instances of those classes can be assigned to the Pen and Brush properties of each diagram element.