The requested page is not available for the requested platform. You are viewing the content for Default platform.

BestSizeEstimator.GetBoundsToFitText(XRLabel, String) Method

Gets boundaries that fit the specified text within the specified control.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public static RectangleF GetBoundsToFitText(
    XRLabel label,
    string text
)
Public Shared Function GetBoundsToFitText(
    label As XRLabel,
    text As String
) As RectangleF

Parameters

Name Type Description
label XRLabel

An XRLabel control whose style and other settings are used in calculations.

text String

A string that specifies the text that should be written to the label in calculations.

Returns

Type Description
RectangleF

A RectangleF structure specifying the control boundaries.

Remarks

The GetBoundsToFitText method allows you to calculate the size that the specified control will have to fit the specified text. You can then apply the resulting rectangle and the specified text to this control or other required controls.

You can also use another GetBoundsToFitText overload to find optimal boundaries for an actual control text.

The code snippet below demonstrates how to use these methods to change the control text if the resulting control height is less than the height with an actual text (the XRControl.Text property value).

using DevExpress.XtraReports.UI;

private void xrLabel1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
    XRLabel label = sender as XRLabel;
    string myText = "Some lengthy content";
    float myHeight = BestSizeEstimator.GetBoundsToFitText(label, myText).Height;
    if (myHeight < BestSizeEstimator.GetBoundsToFitText(label).Height) {
        label.Text = myText;
        label.HeightF = myHeight;
    }
}

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.

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

See Also