Skip to main content

BestSizeEstimator.GetBoundsToFitText(XRLabel) Method

Gets boundaries that fit an actual label text.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core


public static RectangleF GetBoundsToFitText(
    XRLabel label


Name Type Description
label XRLabel

An XRLabel control whose boundaries will be calculated.


Type Description

A RectangleF structure specifying the control boundaries.


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.ComponentModel.EventArgs e) {
    float height = Math.Max(BestSizeEstimator.GetBoundsToFitText(xrLabel1).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 RightToLeft options.


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