Is there any way to draw with code?

Stimulsoft Reports.NET discussion
Post Reply
EnesColak
Posts: 15
Joined: Sat Feb 26, 2022 9:18 am

Is there any way to draw with code?

Post 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.
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Is there any way to draw with code?

Post 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.
Attachments
Screenshot 2022-06-21 103932.png
Screenshot 2022-06-21 103932.png (203.3 KiB) Viewed 639 times
EnesColak
Posts: 15
Joined: Sat Feb 26, 2022 9:18 am

Re: Is there any way to draw with code?

Post by EnesColak »

Thanks for answering. Where is that code part I really cannot find :) BTW the version is 2.1
Attachments
111.png
111.png (19.97 KiB) Viewed 636 times
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Is there any way to draw with code?

Post by Lech Kulikowski »

Hello,

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

Thank you.
EnesColak
Posts: 15
Joined: Sat Feb 26, 2022 9:18 am

Re: Is there any way to draw with code?

Post 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...
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Is there any way to draw with code?

Post by Lech Kulikowski »

Hello,

You should use the Shape component for that task.

Thank you.
EnesColak
Posts: 15
Joined: Sat Feb 26, 2022 9:18 am

Re: Is there any way to draw with code?

Post 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
ulli82
Posts: 47
Joined: Tue Jul 06, 2021 6:46 am

Re: Is there any way to draw with code?

Post by ulli82 »

You can use Shape of type 'Diagonal Up' or 'Down' and set width and height suitable to your angle (simple mathematics).
EnesColak
Posts: 15
Joined: Sat Feb 26, 2022 9:18 am

Re: Is there any way to draw with code?

Post 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."
Attachments
2.png
2.png (30.21 KiB) Viewed 604 times
1.png
1.png (139.38 KiB) Viewed 604 times
ulli82
Posts: 47
Joined: Tue Jul 06, 2021 6:46 am

Re: Is there any way to draw with code?

Post 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.
Post Reply