Skip to main content

BestSizeEstimator.GetBoundsToFitText(String, BrickStyle, ReportUnit) Method

Gets boundaries that fit the specified text with the specified style and system of measurement.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public static RectangleF GetBoundsToFitText(
    string text,
    BrickStyle style,
    ReportUnit reportUnit
)

Parameters

Name Type Description
text String

A string that specifies the text that the resulting boundaries should fit.

style BrickStyle

A BrickStyle object that specifies a drawing style.

reportUnit ReportUnit

A ReportUnit enumeration value that specifies the system of measurement.

Returns

Type Description
RectangleF

A RectangleF structure specifying the resulting boundaries.

Remarks

The GetBoundsToFitText method allows you to calculate the rectangle that fits the specified text taking into account the specified settings.

The code snippet below demonstrates how to use this method to find the optimal size to draw a LabelBrick using the BrickGraphics.DrawBrick method.

using DevExpress.XtraReports.UI;

// Prepare for creating a document.
printingSystem.Begin();
BrickGraphics gr = printingSystem.Graph;
gr.Modifier = BrickModifier.Detail;

// Create a new brick instance and specify its settings.
LabelBrick brick = new LabelBrick();
brick.Text = "Some text";
RectangleF rect = BestSizeEstimator.GetBoundsToFitText(brick.Text, brick.Style, ReportUnit.Pixels);
brick.Rect = rect;

gr.DrawBrick(brick);

// Finish creating the document.
printingSystem.End();

To perform the opposite operation (that is get the font size to fit the specified boundaries), call the BestSizeEstimator.GetFontToFitBounds method.

See Also