Skip to main content

BrickGraphics.MeasureString(String) Method

Measures the specified string when drawn.

Namespace: DevExpress.XtraPrinting

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

NuGet Package: DevExpress.Printing.Core

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

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();

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the MeasureString(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also