This is a migrated thread and some comments may be shown as answers.

Center Multiple Pictures

1 Answer 171 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
George Fryberger
Top achievements
Rank 1
George Fryberger asked on 25 Jan 2012, 06:07 PM
A scenario was presented to determine whether or not Telerik Reporting can handle it.  There are several reports that need to load image files that are defined in the database.  For example the database contains six columns that may be populated with a file name for the image that should be displayed on the report.  At this point I know that I can load the images in this fashion by calling a function that returns an image to set the picturebox value property.  Additionally, in cases where an image is not defined or can not be found I can return a default image (blank.png).

Now I need to add six pictureboxes to my report to allow me to define and display all six images.  I would prefer to do this at design time but if it has be done at runtime I can deal with that.  In some cases I might only be displaying three out of the six images.  In this case, we need to be able to hide the images that are not being displayed and center the remaining images in the container (Panel).  Is this something that can be accomplished either by setting properties or by developing code to handle it?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 27 Jan 2012, 05:09 PM
Hi George,

You can accomplish your requirement with some coding. Just add the images in a panel and check out the following code snippet that illustrates how to conditionally set the panels location based on the images. You may have to refine the sample based on your report and specific requirements.

public partial class Report8 : Telerik.Reporting.Report
{
    public Report8()
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();
        //Set the images panel width to 1 px this will ensure that the images panel will be with the same width as the visible images
        this.imagesPanel.Width = Unit.Pixel(1f);
    }
   
    public static Image GetImage(Processing.ReportItem reportItem)
    {
        var image = Image.FromFile(@"C:\Chrysanthemum.jpg");
      visibleImages--;
      //Get the images panel
      var imagesPanel = (Processing.Panel)reportItem.Report.ChildElements.Find("panel1", true)[0];
       //Set the images panel location based on the number of visible images
      imagesPanel.Location = new PointU(Unit.Inch(visibleImages), Unit.Inch(0));
      return image;
    }
   
    static int visibleImages;
   
    private void Report8_ItemDataBinding_1(object sender, EventArgs e)
    {
        visibleImages = 6;
    }
}


All the best,
Peter
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
George Fryberger
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or