Export (0) Print
Expand All

Graphics.MeasureString(const WCHAR*, INT, const Font*, const RectF, RectF*) method

Applies to: desktop apps only

The Graphics::MeasureString method measures the extent of the string in the specified font and layout rectangle.

Syntax

Status MeasureString(
  [in]       const WCHAR *string,
  [in]       INT length,
  [in]       const Font *font,
  [in, ref]  const RectF &layoutRect,
  [out]      RectF *boundingBox
) const;

Parameters

string [in]

Type: const WCHAR*

Pointer to a wide-character string to be measured.

Important  For bidirectional languages, such as Arabic, the string length must not exceed 2046 characters.

length [in]

Type: INT

Integer that specifies the number of characters in the string array. The length parameter can be set to –1 if the string is null terminated.

font [in]

Type: const Font*

Pointer to a Font object that specifies the family name, size, and style of the font that is applied to the string.

layoutRect [in, ref]

Type: const RectF

Reference to a rectangle that bounds the string.

boundingBox [out]

Type: RectF*

Pointer to a RectF object that receives the rectangle that bounds the string.

Return value

Type:

Type: Status

If the method succeeds, it returns OK, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Examples

The following example measures the size of a string and then draws a rectangle that represents that size.


VOID Example_MeasureString(HDC hdc)
{
   Graphics graphics(hdc);
   // Set up the string.
   WCHAR string[] = L"Measure Text";
   Font font(L"Arial", 16);
   RectF layoutRect(0, 0, 100, 50);
   RectF boundRect;
   // Measure the string.
   graphics.MeasureString(string, 12, &font, layoutRect, &boundRect);
   // Draw a rectangle that represents the size of the string.
   graphics.DrawRectangle(&Pen(Color(255, 0, 0, 0)), boundRect);
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Graphics
DrawString Methods
Font
RectF

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show:
© 2014 Microsoft