BestSizeEstimator Class

Enables you to find optimal boundaries to fit the text, and vice versa, get a font to fit the specified boundaries.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public static class BestSizeEstimator
Public Module BestSizeEstimator

The BestSizeEstimator.GetBoundsToFitText method overloads allow you to calculate a control's size to fit its actual text or any specified text as well as find optimal boundaries for the text with the specified settings.

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;
    }
}

The BestSizeEstimator.GetFontToFitBounds method performs the opposite operation, that is gets the best font size to fit specific boundaries in the maximum possible way.

using DevExpress.XtraReports.UI;

private void xrLabel1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
    XRLabel myLabel = sender as XRLabel;
    Font myFont = BestSizeEstimator.GetFontToFitBounds(myLabel, "Product: " + myLabel.Text);           
    if (myFont.Size > 12) {
        myLabel.Text = "Product: " + myLabel.Text;
        myLabel.Font = myFont;
    }
    else myLabel.Font = BestSizeEstimator.GetFontToFitBounds(myLabel);
}

The GetBoundsToFitContainer method enables you to calculate boundaries for the specified control to occupy the entire space of its parent container (accessed using the Parent property):

// ...
// Fit the picture box to the parent container (table cell or panel).
pictureBox.BoundsF = BestSizeEstimator.GetBoundsToFitContainer(pictureBox);
// ...

Inheritance

Object
BestSizeEstimator

See Also