Page 1 of 1

Is there any way to draw with code?

Posted: Mon Jun 20, 2022 2:22 pm
by EnesColak
I've been trying to draw a line without using shapes, because I need to draw the line with given angle. I've tried to write:


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



to beforeprint event but it does not work.

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 8:39 am
by Lech Kulikowski
Hello,

You should add also start and end points.
The simple way - it is to add the necessary component in the designer, then open the Code Tab and use the same code.

Thank you.

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 9:37 am
by EnesColak
Thanks for answering. Where is that code part I really cannot find :) BTW the version is 2.1

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 11:36 am
by Lech Kulikowski
Hello,

In the JS designer, the Code tab is not available.

Thank you.

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 12:30 pm
by EnesColak
So thats the point... How can I write code to the report for create line with given angle? :)

Is it possible to solve that problem with writing expressions on beforeprint or somewhere else?

I just need to create a polygon with given angles...

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 1:40 pm
by Lech Kulikowski
Hello,

You should use the Shape component for that task.

Thank you.

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 2:29 pm
by EnesColak
I tried to use shapes, but there is not any angle property to write expression sir. That situation is so broken. I think there is no way

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 3:02 pm
by ulli82
You can use Shape of type 'Diagonal Up' or 'Down' and set width and height suitable to your angle (simple mathematics).

Re: Is there any way to draw with code?

Posted: Tue Jun 21, 2022 3:30 pm
by EnesColak
Alright thats right. I can really set the angle with width and height properties, but I could not change the width and height property of that line dynamically,

An example, I have some data like rightAngle and leftAngle like 45-45,
lets say if leftAngle = 45 then myShape.Width = 10 and myShape.Height = 10

the main problem is that, how can I say that in report :)

I've tried some expressions on beforeprint event but its not working.
An error occurs and it says "The script in the 'BeforePrintEvent' event in the 'Shape3' component doesn't work in the interpretation mode."

Re: Is there any way to draw with code?

Posted: Wed Jun 22, 2022 6:12 am
by ulli82
Hi,

please take a look in the manuals to learn about how to use events.

All events has the object to change as parameter (name: sender, type: object). You have to parse this 'sender' to your component type and set your properties on this object.