Graphics::DrawString(constWCHAR*,INT,constFont*,constPointF&,constStringFormat*,constBrush*) method (gdiplusgraphics.h)

The Graphics::DrawString method draws a string based on a font, a string origin, and a format.

Syntax

Status DrawString(
  [in]      const WCHAR        *string,
  [in]      INT                length,
  [in]      const Font         *font,
  [in, ref] const PointF &     origin,
  [in]      const StringFormat *stringFormat,
  [in]      const Brush        *brush
);

Parameters

[in] string

Type: const WCHAR*

Pointer to a wide-character string to be drawn.

[in] length

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.

[in] font

Type: const Font*

Pointer to a Font object that specifies the font attributes (the family name, the size, and the style of the font) to use.

[in, ref] origin

Type: const PointF

Reference to a PointF object that specifies the starting point for the string.

[in] stringFormat

Type: const StringFormat*

Pointer to a StringFormat object that specifies text layout information and display manipulations to be applied to the string.

[in] brush

Type: const Brush*

Pointer to a Brush object that is used to fill the string.

Return value

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.

Remarks

Note that GDI+ does not support PostScript fonts or OpenType fonts which do not have TrueType outlines.

When you use the GDI+ API, you must not allow your application to download arbitrary fonts from untrusted sources. The operating system requires elevated privileges to assure that all installed fonts are trusted.

Examples

The following example uses the specified formatting to draw a string at the specified origin.

VOID Example_DrawString3(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a string.
   WCHAR string[] = L"Sample Text";
   
   // Initialize arguments.
   Font myFont(L"Arial", 16);
   PointF origin(0.0f, 0.0f);
   SolidBrush blackBrush(Color(255, 0, 0, 0));
   StringFormat format;
   format.SetAlignment(StringAlignmentCenter);

   // Draw string.
   graphics.DrawString(
   string,
   11,
   &myFont,
   origin,
   &format,
   &blackBrush);
}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusgraphics.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Font

Graphics

Pen

PointF

StringFormat