Quite often there is a need to set various images in the report depending on any conditions or input parameters. This problem was encountered by the user of the List & Label report generator:
However, the user did not find a solution:
Unfortunately, it is not possible to insert an image from .NET code. This is only possible when working with a report in the List & Label designer.
Therefore, I want to show how this can be implemented in the FastReport.Net report generator.
So, when creating a report, we work directly with all of its objects - create them, add them to the report page, set properties. Consider a simple example of creating a report from the code of a user application with a picture inside.
This is a very simple example of a report with just one ‘data’ band. Since this report is entirely created in the program code, there is no problem to create an object with a picture and put it into the report. Creating a report from the code allows us to change it as much as we want, depending on the logic of the program.
Consider another case. Let's say you already have a report template created in a designer. You want to change the picture in the report depending on the logic of the program. In this case, the report template should already have a Picture object, and you'll just replace the picture itself from the user application code. Here's what the code will look like in the program:
Here, we find an object with a picture in the template of the report and change its properties as desired.
And finally, the third version of the Picture object is from the built-in report script. The report script allows you to change the pattern and data in the report as you like. You can pre-add a Picture object to the template, or you can add it directly to the report script. Truly, limitless flexibility. There is no need to use a custom application to manage the contents of the report. This is a big plus for me, because there is no need to edit the application code.
The example for setting an image in the report script is extremely simple:
You only need to decide on an event in which you want to change a picture, for example, you can use the BeforePrint event for a Picture object.