logo
small logo
  • Products
  • Comprar
  • Suporte
  • Articles
  • Customer panel Suporte
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to set a picture in a report from the user application code
  • FastReport .NET packages e .NET 5.0

    17 de dezembro de 2020

    UPD: aplica-se às versões do FastReport.net antes de 2022.2. Pacotes de licença já estão disponíveis

    read more
  • Relatórios e documentos PDF no Blazor

    5 de abril de 2021

    A Microsoft lançou recentemente uma plataforma web chamada Blazor. Este framework permite a criação de

    read more
  • Create a new report with code VB.NET

    17 de setembro de 2020

    Speaking of the .Net framework, we usually imagine the #C programming language. Simply because the

    read more
  • The Event of ExportParameters in WebReport.Report

    5 de outubro de 2020

    In FastReport 2020.1 we have added the ability to change export parameters. To do this,

    read more
  • PreviewControl.OnPrint and PreviewControl.OnExport Events

    1 de outubro de 2020

    In FastReport 2019.4 added the ability to subscribe to PreviewControl.OnPrint and PreviewControl.OnExport events, which are

    read more

How to set a picture in a report from the user application code

8 de janeiro de 2020

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:

Is there a way to programmatically insert an inline image into a List & Label document from .net code?

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Create instance of class Report
 Report report = new Report();
 //Add report page
 ReportPage page = new ReportPage();
 report.Pages.Add(page);
 page.CreateUniqueName();
 //App data band
 DataBand data = new DataBand();
 //Add data band to page
 page.Bands.Add(data);
 data.CreateUniqueName();
 data.Height = Units.Centimeters * 1; //Set band height
 //Create picture object
 PictureObject pic = new PictureObject();
 pic.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 5); //Set object bounds
 pic.Image = new Bitmap("../../App_Data/snow_flake.ico"); //Set picture
 pic.Parent = data; //Set picture parent object
 pic.CreateUniqueName();
 report.Prepare(); //Build report
 report.Show(); //Show report

 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:         

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 //Create report object
 Report report = new Report();
 //Load report template into the report obj
 report.Load("../../App_Data/Picture.frx");
 //Get picture object from the report template
 PictureObject pic = report.FindObject("Picture1") as PictureObject;
 //Set object bounds
 pic.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 5);
 //Set the image
 pic.Image = new Bitmap("../../App_Data/snow_flake.ico");
 //Build report
 report.Prepare();
 //Show report
 report.Show();

 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:

1
Picture1.Image = new Bitmap("C:/Users/Dimon/source/repos/PictureSetting/PictureSetting/App_Data/snow_flake.ico");

 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.

about product download comprar
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Comprar
  • Download
  • Documentação
  • Depoimentos
  • Como desinstalar nossos produtos
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Informação sobre nós
  • Parceiros
  • Extended licensing
  • Contatos

© 1998-2022 by Fast Reports Inc.

  • Privacidade