TopMarginBand Class
A report band used to display information at the top margin of every report page. The End User Report Designer does not allow you to remove this band from a report.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v25.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Remarks
A blank report contains the DetailBand, TopMarginBand and BottomMarginBand. These bands cannot be deleted in the Report Designer.
The top margin band’s content is printed at the top of every report page, above all other bands.
For a printer, this is the non-printable document area (so-called hardware printer margins). When a report is exported to DOCX format, the content of the TopMarginBand appears in the native Microsoft Word document margins.
This band is used to display auxiliary information about a report, such as page numbers or the current system date and time in the XRPageInfo control.
The height of margin bands is defined by the report’s Margins property. Margin bands do not adjust their height to fit content. Content is cropped if it extends beyond the right edge of the band.
To display an image on every document page and adjust band height based on a loaded image, use the Page Header or Page Footer bands instead.
The report controls placed in this band may export to PDF differently than when placed in DetailBand, ReportHeaderBand, or ReportFooterBand. Use the PrintMode parameter to adjust how the controls are rendered when exported to PDF.
Margin bands actually is a non-printable document area (so-called hardware printer margins) Exporting these bands content to DOCX - content from margin bands goes to native Word margins.
Tip
Use the BottomMarginBand to display this information at the bottom of every report page.
Review the following help topic for information about report bands: Introduction to Banded Reports.
Example
The following example demonstrates how to use the BandCollection class methods to construct a simple report. The AddMarginBands method creates two margin bands and adds them to the collection.
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
// ...
// ...
// Generated code for the XtraReport1 class.
// ...
public void AddMarginBands() {
// Check if the TopMargin band is already present in the report.
if(Bands[BandKind.TopMargin] == null) {
// Create a new TopMargin band and add it to the report.
TopMarginBand tmBand = new TopMarginBand();
Bands.Add(tmBand);
// Create a label and set its text and width.
XRLabel label = new XRLabel();
label.Text = "TopMargin Band";
label.Width = 200;
// Add the label to the TopMargin band.
tmBand.Controls.Add(label);
}
// Check if the BottomMargin band is already present in the report.
if(Bands[BandKind.BottomMargin] == null) {
// Create a new BottomMargin band and add it to the report.
BottomMarginBand bmBand = new BottomMarginBand();
Bands.Add(bmBand);
// Create an XRPageInfo object and set its width and PageInfo option.
XRPageInfo datePageInfo = new XRPageInfo();
datePageInfo.Width = 200;
datePageInfo.PageInfo = PageInfo.DateTime;
// Add the page information control to the BottomMargin band.
bmBand.Controls.Add(datePageInfo);
}
}
}
The following code handles button clicks to call the AddMarginBands method and show the preview:
XtraReport1 report = new XtraReport1();
private void btnPreview_Click(object sender, System.EventArgs e) {
ReportPrintTool preview = new ReportPrintTool(report);
preview.ShowPreview();
}
private void btnAddBands_Click(object sender, System.EventArgs e) {
report.AddMarginBands();
}