New to Telerik Reporting? Download free 30-day trial

Create custom shape

Environment

Product Progress® Telerik® Reporting

Description

There are multiple Shapes already available out of the box to utilize in Telerik Reporting reports. We provide also an option to create Custom Shapes. Here is how to do it.

Solution

  1. The ShapeType must be set to a new implementation of the ShapeBase class, i.e. create new class to represent the new custom shape:

      class MyCustomShape : Telerik.Reporting.Drawing.Shapes.ShapeBase
    
  2. The method CreateShape() of the new class should be overridden to create the corresponding shape/geometry of the custom shape:

      protected override void CreateShape()
      {
          //DESCRIBE THE GEOMETRY OF THE CUSTOM SHAPE HERE
    
          PointF[] seriesofPoints = new PointF[8];
          seriesofPoints[0] = new PointF(-10, 10);
          seriesofPoints[1] = new PointF(-10, 4);
          seriesofPoints[2] = new PointF(-12, 4);
          seriesofPoints[3] = new PointF(-12, 0);
          seriesofPoints[4] = new PointF(12, 0);
          seriesofPoints[5] = new PointF(12, 4);
          seriesofPoints[6] = new PointF(10, 4);
          seriesofPoints[7] = new PointF(10, 10);
    
          base.AddLines(seriesofPoints, true);
      }
    
  3. The Clone() method should also be overridden to return the new shape:

      public override object Clone()
      {
          return new MyCustomShape()
          {
              Bounds = this.Bounds
          };
      }
    

After the Custom Shape has been created, it can be instantiated and added to the report.

Here is a sample demonstrating the approach.

Notes

The geometry of MyCustomShape in the sample should be changed according to the specific requirements by modifying the CreateShape() method body using the functionality of the System.Drawing namespace.

The project ReportLibrary1 should be built before previewing Report1, where a single MyCustomShape item is added in the constructor.

In this article