Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

BestSizeEstimator.GetFontToFitBounds(String, BrickStyle, RectangleF, ReportUnit) Method

Gets the font with which the specified text fits the specified boundaries.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

#Declaration

public static DXFont GetFontToFitBounds(
    string text,
    BrickStyle style,
    RectangleF bounds,
    ReportUnit reportUnit
)

#Parameters

Name Type Description
text String

A string that specifies the text used in calculations.

style BrickStyle

A BrickStyle object that specifies a drawing style.

bounds RectangleF

A RectangleF structure specifying the initial boundaries which the text should fit.

reportUnit ReportUnit

A ReportUnit enumeration value that specifies the system of measurement.

#Returns

Type Description
DXFont

An optimal font.

#Remarks

The GetFontToFitBounds method allows you to calculate an optimal font for the specified text to occupy the entire specified area.

The code snippet below demonstrates how to use this method to draw a LabelBrick with maximum possible text size.

using DevExpress.XtraReports.UI;
using DevExpress.Drawing;

// 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";
brick.Rect = new RectangleF(0, 0, 200, 100);
DXFont font = BestSizeEstimator.GetFontToFitBounds(brick.Text, brick.Style, brick.Rect, ReportUnit.Pixels);
brick.Style.Font = font;
gr.DrawBrick(brick);

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

To perform the opposite operation (that is get the boundaries to fit the specified text), call the BestSizeEstimator.GetBoundsToFitText method.

See Also