BrickGraphics.MeasureString(String, Int32) Method
Measures the specified string when drawn with the specified maximum width.
Namespace: DevExpress.XtraPrinting
Assembly: DevExpress.Printing.v22.2.Core.dll
NuGet Packages: DevExpress.Printing.Core, DevExpress.Win.Dashboard.Design
Declaration
Parameters
Name | Type | Description |
---|---|---|
text | String | String to measure. |
width | Int32 | An integer value specifying the maximum width of the measured string. |
Returns
Type | Description |
---|---|
SizeF | This method returns a SizeF structure that represents the size, measured in pixels. |
Remarks
This method measures a 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. If measured string width exceeds the width parameter value, then the height parameter value of the returned SizeF structure is increased, in order to fit inside the measured string.
Example
This example calculates the dimensions of the rectangle to fit the specified string with a limitation on maximum width (75 measurement units). Then, a report with the VisualBrick, containing the string, is created and displayed.
Tip
A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e78/how-to-measure-the-size-of-the-text-block.
using DevExpress.XtraPrinting;
// ...
VisualBrick visBrick;
BrickGraphics brickGraph = printingSystem1.Graph;
string s = "Developer Express Inc.";
// Measure the string, specifying the maximum width.
SizeF sz = brickGraph.MeasureString(s, 75);
// 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 text 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();
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the MeasureString(String, Int32) 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.