Extension to insert non-text related objects

4 posts, 1 answers
  1. Jason
    Jason avatar
    2 posts
    Member since:
    May 2018

    Posted 11 Jun Link to this post

    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?

  2. Answer
    Ivan Hristov
    Admin
    Ivan Hristov avatar
    169 posts

    Posted 14 Jun Link to this post

    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
  3. Jason
    Jason avatar
    2 posts
    Member since:
    May 2018

    Posted 14 Jun in reply to Ivan Hristov Link to this post

    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?

  4. Ivan Hristov
    Admin
    Ivan Hristov avatar
    169 posts

    Posted 15 Jun Link to this post

    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
Back to Top