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

Extension to insert non-text related objects

3 Answers 38 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 11 Jun 2018, 08:07 PM

I find the ability to create user functions so that the users of the designer can insert domain related content. However, there are some places where I would like to help them insert objects other than text.

Is it possible to provide a function that would return, say, a shape or other visual element?

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Hristov
Telerik team
answered on 14 Jun 2018, 12:22 PM
Hi Jason,

The idea of user functions is to provide a value or modify a property for already existing item during the processing stage. Any new report item must be created before the report is processed - we usually advise to do that right after InitializeComponent() method in report constructor.

If you need to create a new shape item, this can be achieved the following way:
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 like this:
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
0
Jason
Top achievements
Rank 1
answered on 14 Jun 2018, 06:31 PM

I guess that makes sense. Since user functions provide values to generally textual property values, they only really need return string values.

Is there listed anywhere all of the places that user functions can be used? I guess that would be, all of the properties that can have an Expression value?

0
Ivan Hristov
Telerik team
answered on 15 Jun 2018, 01:35 PM
Hi Jason,

The user functions can be used to provide not only textual information, but also binary contents (Image for PictureBox), location coordinates in order to change position of an item, or a Color - when needed to set the color of some item through Bindings

Basically expressions can be used on every property that shows the Edit Expression dialog when edited. Even more, some properties can be adjusted via Bindings even if they do not provide a way to set an expression directly. However, some properties like Shape's ShapeType cannot be set this way.

Hope that helps.

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
Jason
Top achievements
Rank 1
Answers by
Ivan Hristov
Telerik team
Jason
Top achievements
Rank 1
Share this question
or