New to Telerik UI for WinForms? Download free 30-day trial

Custom shapes

This tutorial will guide you through the task of creating a custom shape.

Creating custom shapes programmatically

In order to create a custom shape, you need to define a custom shape class deriving from the ElementShape class. Overriding its CreatePath method you can define the desired shape. Afterwards, you need to apply your shape implementation to the RadDiagramShape.ElementShape property:


public class MyShape : ElementShape
{
    public override GraphicsPath CreatePath(System.Drawing.Rectangle bounds)
    {
        GraphicsPath path = new GraphicsPath();
        path.AddString("Custom", new System.Drawing.FontFamily("Arial"), 0, bounds.Width, Point.Empty, StringFormat.GenericTypographic);
        return path;
    }
}

RadDiagramShape shape1 = new RadDiagramShape()
{
    ShapeText = "",
    ElementShape = new MyShape(),
    InternalElementColor = System.Drawing.Color.LightBlue
};
shape1.Position = new Telerik.Windows.Diagrams.Core.Point(100, 80);
radDiagram1.AddShape(shape1);

WinForms RadDiagram Custom Shapes

Creating custom shapes by the Custom Shape Editor

When you open the RadDiagram Property Builder from the Smart Tag and drag a shape from the toolbox you can customize the default shape by editing the ElementShape property and selecting the Create new custom shape ... option from the list:

WinForms RadDiagram Shape Editor

This will display the Custom Shape Editor.

WinForms RadDiagram Custom Shape using Editor