I want to create a XtraReport Template class, which get a report object and transform it to our Company design. At first, I create a ReportHeaderBand which get an XRPictureBox for the Logo. How can I place the XRPictureBox at the Right side of my ReportHeaderBand?
This is what I am doing so far:
internal class Kopfbereich: ReportHeaderBand
{
/// <summary>
/// Erstellt ein Objekt für den Kopfbereich eines Reports
/// </summary>
public Kopfbereich()
{
DruckeLogo();
}
private void DruckeLogo()
{
XRPictureBox picBox = new XRPictureBox();
picBox.Visible = true;
picBox.Sizing = ImageSizeMode.AutoSize;
picBox.Image = Resources.Brillux_Logo_Reports_ohne_Text;
this.Controls.Add(picBox);
}
}
//This Method is from other class and should print my report with template
public XtraReport DruckeMitVorlage(XtraReport report)
{
Kopfbereich kopfbereich = new Kopfbereich();
report.Bands.Add(kopfbereich);
return report;
}
I want to create it at Runtime to get an dynamic Template. So Designer is not an option.
I tried following code line to set the XRPictureBox on the right.
picBox.LocationF = new PointF(Report.PageWidth - picBox.WidthF - Report.Margins.Right.Width, 0);
But the Logo becomes displayed half on the next page.
I suggest you to add this XRPictureBox
control to the report header band
rather than this.Controls
. It may control the picture edit to print on the top of the report rather than printing on another pages..
check the code snippet:
// Check if the TopMargin band is already present in the report.
if(Bands.GetBandByType(typeof(ReportHeaderBand)) == null) {
// Create a new TopMargin band and add it to the report.
ReportHeaderBandtmBand = new ReportHeaderBand();
Bands.Add(tmBand);
// Create a picture object
XRPictureBox picBox = new XRPictureBox();
picBox.Visible = true;
picBox.Sizing = DevExpress.XtraPrinting.ImageSizeMode.AutoSize;
picBox.Image = Resources.Logo;
this.Controls.Add(picBox);
// Add the label to the ReportHeaderBand band.
tmBand.Controls.Add(picBox);
}
You can place control using report object as below:
// Place the chart onto a report footer
rep.Bands[BandKind.ReportHeader].Controls.Add(picBox);
Reference:
How to create a report dynamically in the WinForms application