This is a migrated thread and some comments may be shown as answers.

Creating Custom Polygon Shape

2 Answers 188 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Dondon
Top achievements
Rank 1
Dondon asked on 06 Dec 2017, 04:10 AM

Hi,

 

I hope anyone can help me on this as my situation is very urgent. If you can see on the attached file, that is the shape that I want to make. So I decided to use the polygon shape which is available in telerik. Below is my sample code :

Telerik.Reporting.Shape polygonShape = new Telerik.Reporting.Shape();

PolygonShape seriesofPolygonShapePoints = new PolygonShape(8,0,0);

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);

seriesofPolygonShapePoints.AddLines(points, true);

#region create custom polygon shape
polygonShape = new Telerik.Reporting.Shape
{
ShapeType = seriesofPolygonShapePoints,
Size = new SizeU(
Unit.Inch(.10),
Unit.Inch(.10)),
Stretch = true,
Location = new PointU(
Unit.Inch(coordinateViewModel.LocationOfX),
Unit.Inch(coordinateViewModel.LocationOfY)),
Style = {
BackgroundColor = backgroundColor,
Color = color,
LineWidth = lineWidth
}
};
#endregion
#region add to section
detailSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
polygonShape,
});
#endregion

 

With the above code, the report runs but it doesn't draw properly. It draws the default octagon shape since it has eight side. BUT what I want is the image I attached should display since I provided the points where the line should draw.

I don't know if im missing something in the code or am I missing the points that I need to add to draw the shape properly..

Hope someone can help me immediately..

 

Thanks!!!

2 Answers, 1 is accepted

Sort by
0
Dondon
Top achievements
Rank 1
answered on 06 Dec 2017, 05:19 AM

Also while im checking in the design view, when added the Shape Control from the telerik object, there is a shapetype property where it only list the available shape that can be used. Since my shape is customized, is it even possible to create a custom shape based on my attached image above?

Need everyone's help especially the experts of telerik devs..

0
Ivan Hristov
Telerik team
answered on 06 Dec 2017, 01:59 PM
Hi Dondon,

This question has been answered in the support ticket you posted, but I will paste the information here so anyone interested could find it:

When creating a custom shape, the ShapeType property must be set to a new implementation of the ShapeBase class, as shown below:
class MyCustomShape : Drawing.Shapes.ShapeBase
    {
        public override object Clone()
        {
            return new MyCustomShape()
            {
                Bounds = this.Bounds
            };
        }
  
        protected override void CreateShape()
        {          
            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);
        }
    }

The shape item can be instantiated and added to the report the following way:
IReportDocument CreateReport()
        {
            var report = new MyReport();
            var detailsSection = report.Items.OfType<DetailSection>().FirstOrDefault();
            detailsSection.Items.Add(this.CreateShape());
  
            return report;
        }
  
        Shape CreateShape()
        {
            var shape = new Shape()
            {
                ShapeType = new MyCustomShape(),
                Size = new Drawing.SizeU(Drawing.Unit.Cm(2), Drawing.Unit.Cm(2)),
                Location = new Drawing.PointU(Drawing.Unit.Cm(1), Drawing.Unit.Cm(1))
            };
            return shape;
        }

The code above will produce a report that has the desired shape in its details section. Currently there is no way to add a design-time support for custom ShapeType implementations, but using code, as demonstrated above, allows to add virtually any kind of shape to a report.


Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Report Designer (standalone)
Asked by
Dondon
Top achievements
Rank 1
Answers by
Dondon
Top achievements
Rank 1
Ivan Hristov
Telerik team
Share this question
or