Draw line at runtime

Stimulsoft Reports.WPF discussion
Post Reply
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Draw line at runtime

Post by Prandl33 »

Hello,
it is possible to render a line at runtime, as shown below, on a page.
After loading the mrt, I want to draw the line before I compile the report.

Code: Select all

        private void SetLineOnPage(StiReport report) {

            StiPage page1= (StiPage) report.GetComponentByName("Page1");

                StiVerticalLinePrimitive lineVertikal;
                lineVertikal = new Stimulsoft.Report.Components.StiVerticalLinePrimitive();
                lineVertikal.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(24, 1, 0.0254, 16);
                lineVertikal.Color = System.Drawing.Color.Black;
                Guid guid = Guid.NewGuid();
                lineVertikal.Guid = guid.ToString();
                lineVertikal.Name = "LineVertikalDick";
                lineVertikal.Size = 3F;
                lineVertikal.EndCap = new StiCap(10, Stimulsoft.Base.Drawing.StiCapStyle.None, 10, true, System.Drawing.Color.Black);
                lineVertikal.Interaction = null;
                lineVertikal.StartCap = new StiCap(10, Stimulsoft.Base.Drawing.StiCapStyle.None, 10, true, System.Drawing.Color.Black);

                lineVertikal.Page = page1;
                lineVertikal.Parent = page1;

                page1.Components.AddRange(new Stimulsoft.Report.Components.StiComponent[] {
                        lineVertikal});
            }
        }
This way don't work. How can I solve this problem.
Thank you
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Re: Draw line at runtime

Post by Prandl33 »

Hello,
now I found out that the following code works in the OnPageBeforePrint event.

Code: Select all

 
       private void SetLinesHorizontal(StiPage page) {

            StiHorizontalLinePrimitive lineHorizontal;
            lineHorizontal = new Stimulsoft.Report.Components.StiHorizontalLinePrimitive();
            lineHorizontal.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(2, 2, 6, 0.5);
            lineHorizontal.Color = System.Drawing.Color.Red;
            lineHorizontal.Name = "LineHorizontal";
            lineHorizontal.Size = 3F;
            page.Components.Add(lineHorizontal);
        }
But the same Code for a vertical line doesn't work.
For example like this:

Code: Select all

        private void SetLinesVertikal(StiPage page) {

            StiVerticalLinePrimitive lineVertical;
            lineVertical = new Stimulsoft.Report.Components.StiVerticalLinePrimitive();
            lineVertical.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3, 3, 0.5, 6.4);
            lineVertical.Color = System.Drawing.Color.Red;
            lineVertical.Name = "LineVertical";
            lineVertical.Size = 3F;
            page.Components.Add(lineVertical);
        }
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Draw line at runtime

Post by Edward »

Hi Prandl,

The easy way I always check in order to understand the behaviour any specific component, I create that simple shape or any other component and go to the Code tab in the .Net designer, where I can see the behaviour of any specific component. This is a similar case. I found out, that the start point and end point properties are required in that case as well! Please check it out:

Code: Select all

            // 
            // VerticalLinePrimitive1
            // 
            this.VerticalLinePrimitive1 = new Stimulsoft.Report.Components.StiVerticalLinePrimitive();
            this.VerticalLinePrimitive1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3.4, 0.2, 0.0254, 3.4);
            this.VerticalLinePrimitive1.Color = System.Drawing.Color.Black;
            this.VerticalLinePrimitive1.Guid = "78e1030a07304c9fbda86e15b6c468bc";
            this.VerticalLinePrimitive1.Name = "VerticalLinePrimitive1";
            this.VerticalLinePrimitive1.EndCap = new Stimulsoft.Base.Drawing.StiCap(10, Stimulsoft.Base.Drawing.StiCapStyle.None, 10, true, System.Drawing.Color.Black);
            this.VerticalLinePrimitive1.Interaction = null;
            this.VerticalLinePrimitive1.StartCap = new Stimulsoft.Base.Drawing.StiCap(10, Stimulsoft.Base.Drawing.StiCapStyle.None, 10, true, System.Drawing.Color.Black);
            // 
            // StartPointPrimitive1
            // 
            this.StartPointPrimitive1 = new Stimulsoft.Report.Components.StiStartPointPrimitive();
            this.StartPointPrimitive1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3.4, 0.2, 0, 0);
            this.StartPointPrimitive1.Name = "StartPointPrimitive1";
            this.StartPointPrimitive1.ReferenceToGuid = "78e1030a07304c9fbda86e15b6c468bc";
            this.StartPointPrimitive1.Interaction = null;
            // 
            // EndPointPrimitive1
            // 
            this.EndPointPrimitive1 = new Stimulsoft.Report.Components.StiEndPointPrimitive();
            this.EndPointPrimitive1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3.4, 3.6, 0, 0);
            this.EndPointPrimitive1.Name = "EndPointPrimitive1";

....

           this.Page1.Components.AddRange(new Stimulsoft.Report.Components.StiComponent[] {
                        this.VerticalLinePrimitive1,
                        this.StartPointPrimitive1,
                        this.EndPointPrimitive1});


so the answer here is that you would need to take care of the 'start' and the 'end' points of the vertical line primitive!

Thank you,
Edward
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Re: Draw line at runtime

Post by Prandl33 »

Hello Edward!
I also look at the code, what was generated there.
At this moment I checked that the start point and the entpoint have to be defined with a vertical line.
Thank you very much!

Now it works fine:

Code: Select all

            
            StiVerticalLinePrimitive lineVertical = new Stimulsoft.Report.Components.StiVerticalLinePrimitive();
            lineVertical.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3, 3, 0.5, 6.4);
            lineVertical.Color = System.Drawing.Color.Red;
            Guid guid = Guid.NewGuid();
            lineVertical.Guid = guid.ToString();
            lineVertical.Name = "LineVertical";
            lineVertical.Size = 3F;
            page.Components.Add(lineVertical);

            StiStartPointPrimitive startPoint = new Stimulsoft.Report.Components.StiStartPointPrimitive();
            startPoint.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3, 3, 0, 0);
            startPoint.Name = "StartPoint";
            startPoint.ReferenceToGuid = guid.ToString();
            page.Components.Add(startPoint);

            StiEndPointPrimitive endPoint = new Stimulsoft.Report.Components.StiEndPointPrimitive();
            endPoint.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(3, 9.4, 0, 0);
            endPoint.Name = "EndPoint";
            endPoint.ReferenceToGuid = guid.ToString();
            page.Components.Add(endPoint);
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Draw line at runtime

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need our help.

Thank you.
Post Reply