Skip to main content
All docs
V24.1

Use Helper Classes

  • 2 minutes to read

This section lists helper classes you can use to customize report rendering and implement additional functionality into reporting applications.

Graphics Utilities

GraphicsUnitConverter

Converts values to different measurement units.

The code sample below calculates the clipping region of the drawing surface. The Graphics measurement unit is Document and the report measurement unit is specified by the XtraReport.ReportUnit property.

var clipBounds = GraphicsUnitConverter.Convert(report.PageSize, report.Dpi, GraphicsDpi.Document);

For more information, review the following help topic: Report Units of Measurement.

BestSizeEstimator

Allows you to find the optimal boundaries for a font or get a font that fits the boundaries.

The following code adjusts the font to fit the XRLabel:

label.Font = BestSizeEstimator.GetFontToFitBounds(label);

Data Source Utility

DataSourceManager

When you create a reporting application, you might need to modify or configure data sources for your reports at runtime. Refer to the following topic for more information: Manage Data Sources at Runtime.

The following code replaces the report’s data sources with the test data sources:

foreach(var ods in DataSourceManager.GetDataSources<ObjectDataSource>(report)) {
    TestObjectDataSource tds = new TestObjectDataSource(ods.Container) {
        Constructor = ods.Constructor,
        DataMember = ods.DataMember,
        DataSource = ods.DataSource,
        Name = ods.Name
    };
    tds.Parameters.AddRange(ods.Parameters);
    DataSourceManager.ReplaceDataSource(report, ods, tds);
}

Page Rendering Utility

BrickSelector

Locates visual bricks in a document or on the specified document page. For more information on bricks, review the following help topic: Bricks.

The following code hides report elements in a document whose predecessors in a report (report controls) are tagged with the XRControl.Tag property set to “hide this”:

void Report_AfterPrint(object sender, EventArgs e) {
    XtraReport report = (XtraReport)sender;
    DevExpress.XtraPrinting.VisualBrick brick;
    brick = BrickSelector.GetBricksByTag(report.PrintingSystem.Document.Pages[0], "hide this").FirstOrDefault();
    brick.IsVisible = false;
}