SpriteFont.MeasureString Method (StringBuilder)

Returns the width and height of a string as a Vector2.

Syntax

'Declaration
Public Function MeasureString ( _
         text As StringBuilder _
) As Vector2 
public Vector2 MeasureString (
         StringBuilder text
)
public:
Vector2 MeasureString(
         StringBuilder text
)

Parameters

Return Value

Type: Vector2
The width and height, in pixels, of text, when it is rendered.

Exceptions

Exception type Condition
ArgumentNullException text cannot be null.
ArgumentException There is a character in text that was not imported by the SpriteFont. You must include all the characters in the character regions in the sprite font file. For more information, see How to: Extend the Font Description Processor to Support Additional Characters.

Remarks

Use a StringBuilder argument in place of a String argument to measure dynamically formatted text.

Requirements

Namespace: Microsoft.Xna.Framework.Graphics

Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)

See Also

Reference

SpriteFont Class
SpriteFont Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Windows Phone