Back to Devexpress

BestSizeEstimator.GetFontToFitBounds(XRLabel) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-bestsizeestimator-dot-getfonttofitbounds-x28-devexpress-dot-xtrareports-dot-ui-dot-xrlabel-x29.md

latest3.5 KB
Original Source

BestSizeEstimator.GetFontToFitBounds(XRLabel) Method

Gets the font with which the label actual text fits its boundaries.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public static DXFont GetFontToFitBounds(
    XRLabel label
)
vb
Public Shared Function GetFontToFitBounds(
    label As XRLabel
) As DXFont

Parameters

NameTypeDescription
labelXRLabel

An XRLabel control whose boundaries will be used in calculations.

|

Returns

TypeDescription
DXFont

An optimal font.

|

Remarks

The GetFontToFitBounds method allows you to calculate a font size for a control’s actual text (the XRControl.Text property value) to fit the control’s boundaries. You can then apply the resulting font to this control or other required controls.

The code snippet below demonstrates how to use this method.

csharp
using DevExpress.XtraReports.UI;

private void xrLabel1_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
    XRLabel label = sender as XRLabel;
    label.Font = BestSizeEstimator.GetFontToFitBounds(label);
}
vb
Imports DevExpress.XtraReports.UI

Private Sub xrLabel1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs)
    Dim label As XRLabel = TryCast(sender, XRLabel)
    label.sFont = BestSizeEstimator.GetFontToFitBounds(label)
End Sub

If a control is bound to data, call this method when the corresponding binding has already been evaluated (for instance, in the XRControl.BeforePrint event handler).

This method’s result depends on the control’s XRControl.WordWrap option.

Note

This method is not supported when the XRLabel.Angle property is specified.

You can also use another GetFontToFitBounds overload to find the optimal font size for any specified text.

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

See Also

GetBoundsToFitText

BestSizeEstimator Class

BestSizeEstimator Members

DevExpress.XtraReports.UI Namespace