Back to Devexpress

XtraReport.Margins Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-a60bbef3.md

latest6.3 KB
Original Source

XtraReport.Margins Property

Gets or sets the report’s page margins.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[SRCategory(ReportStringId.CatPageSettings)]
[XRLocalizable(true)]
public DXMargins Margins { get; set; }
vb
<SRCategory(ReportStringId.CatPageSettings)>
<XRLocalizable(True)>
Public Property Margins As DXMargins

Property Value

TypeDescription
DXMargins

The report’s page margins.

|

Remarks

Margins are measured in report units (hundredths of an inch or tenths of a millimeter).

To set report margins, create a new DXMargins object and assign it to the XtraReport.Margins property. Do not change an individual setting (Top / Left / Bottom / Right) in the DXMargins object obtained with the XtraReport.Margins property.

Example

The code sample below creates a new report, sets its name, display name, paper kind and margins, and adds the Detail Band band with the XRLabel control on it.

csharp
using System.Drawing;
using DevExpress.Drawing;
using DevExpress.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...
public static XtraReport CreateReport() {
    XtraReport report = new XtraReport() {
        Name = "SimpleStaticReport",
        DisplayName = "Simple Static Report",
        PaperKind = DXPaperKind.Letter,
        Margins = new DXMargins(100, 100, 100, 100)
    };

    DetailBand detailBand = new DetailBand() {
        HeightF = 25
    };
    report.Bands.Add(detailBand);

    XRLabel helloWordLabel = new XRLabel() {
        Text = "Hello, World!",
        Font = new DXFont("Tahoma", 20f, DXFontStyle.Bold),
        BoundsF = new RectangleF(0, 0, 250, 50),
    };
    detailBand.Controls.Add(helloWordLabel);

    return report;
}
vb
Imports System.Drawing
Imports System.Drawing.Printing
Imports DevExpress.Drawing
Imports DevExpress.Drawing.Printing
Imports DevExpress.XtraReports.UI
' ...
Public Shared Function CreateReport() As XtraReport
    Dim report As New XtraReport() With {
        .Name = "SimpleStaticReport",
        .DisplayName = "Simple Static Report",
        .PaperKind = DXPaperKind.Letter,
        .Margins = New DXMargins(100, 100, 100, 100)}

    Dim detailBand As New DetailBand() With {
        .HeightF = 25}
    report.Bands.Add(detailBand)

    Dim helloWordLabel As New XRLabel() With {
        .Text = "Hello, World!",
        .Font = New DXFont("Tahoma", 20.0F, DXFontStyle.Bold),
        .BoundsF = New RectangleF(0, 0, 250, 50)}
    detailBand.Controls.Add(helloWordLabel)

    Return report
End Function

The following code snippets (auto-collected from DevExpress Examples) contain references to the Margins property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-label-report-in-code/CS/Reporting_how-to-create-a-label-report-at-runtime-t473792/LabelReportRuntime/CustomLabelReportBuilder.cs#L46

csharp
int bottom = (int)XRConvert.Convert(model.BottomMargin, labelDpi, report.Dpi);
report.Margins = new Margins(left, right, top, bottom);
float labelWidth = XRConvert.Convert(model.LabelWidth, labelDpi, report.Dpi);

reporting-wpf-wizard-custom-page/CS/WizardCustomizationService.cs#L49

csharp
report.PaperKind = customModel.PaperKind;
report.Margins = customModel.PageMargins;
builder.Build(report, customModel);

reporting-winforms-label-report-in-code/VB/Reporting_how-to-create-a-label-report-at-runtime-t473792/LabelReportRuntime/CustomLabelReportBuilder.vb#L46

vb
Dim bottom As Integer = CInt((XRConvert.Convert(model.BottomMargin, labelDpi, report.Dpi)))
report.Margins = New Margins(left, right, top, bottom)
Dim labelWidth As Single = XRConvert.Convert(model.LabelWidth, labelDpi, report.Dpi)

reporting-wpf-wizard-custom-page/VB/WizardCustomizationService.vb#L53

vb
report.PaperKind = customModel.PaperKind
report.Margins = customModel.PageMargins
builder.Build(report, customModel)

See Also

Report Units of Measurement

XtraReport Class

XtraReport Members

DevExpress.XtraReports.UI Namespace