MeasureString Method (String)
Collapse the table of content
Expand the table of content

SpriteFont.MeasureString Method (String)

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

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in

public Vector2 MeasureString (
         string text


Type: String
The string to measure.

Return Value

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

Exception typeCondition
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.

Xbox 360, Windows 7, Windows Vista, Windows XP

Community Additions

© 2016 Microsoft