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

BrickGraphics.MeasureString(String) Method

Measures the specified string when drawn.

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v19.2.Core.dll

Declaration

public SizeF MeasureString(
    string text
)

Parameters

Name Type Description
text String

String to measure.

Returns

Type Description
SizeF

This method returns a SizeF structure that represents the size, measured in pixels.

Remarks

This method measures the text string specified via the parameter. The resulting string size is determined not only by the string’s contents, but also by the BrickGraphics.Font property value.

Example

This example illustrates the BrickGraphics.MeasureString method to calculate the dimensions of the rectangle to fit a string. Then, it creates a VisualBrick, containing the measured string, and displays it in a preview form.

MeasureString1

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E78.

using DevExpress.XtraPrinting;
// ...

    VisualBrick visBrick;
    BrickGraphics brickGraph = printingSystem1.Graph;
    string s = "Developer Express Inc.";

    // Determine the visual dimensions of the string.
    SizeF sz = brickGraph.MeasureString(s);

    // Start the report generation.
    printingSystem1.Begin();

    // Specify a page area.
    brickGraph.Modifier = BrickModifier.Detail;

    // Create a rectangle of the calculated size plus the border dimensions.
    RectangleF rect = new RectangleF(new PointF(0, 0), sz);
    rect = brickGraph.DefaultBrickStyle.InflateBorderWidth(rect, GraphicsDpi.Pixel);
    rect.Offset(-rect.X, -rect.Y);

    // Add a brick to the report.
    visBrick = brickGraph.DrawString(s, Color.Black, rect, BorderSide.All);

    // Finish the report generation.
    printingSystem1.End();

    // Preview the report.
    printingSystem1.PreviewFormEx.Show();
See Also