Skip to main content
A newer version of this page is available. .

BestSizeEstimator.GetBoundsToFitText(XRLabel) Method

Gets boundaries that fit an actual label text.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.1.dll

NuGet Packages: DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Core

Declaration

public static RectangleF GetBoundsToFitText(
    XRLabel label
)

Parameters

Name Type Description
label XRLabel

An XRLabel control whose boundaries will be calculated.

Returns

Type Description
RectangleF

A RectangleF structure specifying the control boundaries.

Remarks

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

The code snippet below demonstrates how to use this method to make several controls in the Detail band have the same height.

using DevExpress.XtraReports.UI;

private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
    float height = Math.Max(BestSizeEstimator.GetBoundsToFitText(xrLabel1).Height,
        BestSizeEstimator.GetBoundsToFitText(xrLabel2).Height);
    xrLabel1.HeightF = xrLabel2.HeightF = xrPictureBox1.HeightF = height;
}

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, XRControl.TextAlignment and XRControl.RightToLeft options.

Note

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

You can also use another GetBoundsToFitText overload to find optimal boundaries for any specified text.

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

See Also