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.GetBoundsToFitText(XRLabel) Method

Gets boundaries that fit an actual label text.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.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.ComponentModel.EventArgs 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 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