Graphics::DrawString(constWCHAR*,INT,constFont*,constRectF&,constStringFormat*,constBrush*) method (gdiplusgraphics.h)
The Graphics::DrawString method draws a string based on a font, a layout rectangle, and a format.
Syntax
Status DrawString(
const WCHAR *string,
INT length,
const Font *font,
const RectF & layoutRect,
const StringFormat *stringFormat,
const Brush *brush
);
Parameters
string
Pointer to a wide-character string to be drawn.
length
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
Pointer to a Font object that specifies the font attributes (the family name, the size, and the style of the font) to use.
layoutRect
Reference to a rectangle that bounds the string.
stringFormat
Pointer to a StringFormat object that specifies text layout information and display manipulations to be applied to the string.
brush
Pointer to a Brush object that is used to fill the string.
Return value
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 in a layout rectangle.
VOID Example_DrawString(HDC hdc)
{
Graphics graphics(hdc);
// Create a string.
WCHAR string[] = L"Sample Text";
// Initialize arguments.
Font myFont(L"Arial", 16);
RectF layoutRect(0.0f, 0.0f, 200.0f, 50.0f);
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
SolidBrush blackBrush(Color(255, 0, 0, 0));
// Draw string.
graphics.DrawString(
string,
11,
&myFont,
layoutRect,
&format,
&blackBrush);
// Draw layoutRect.
graphics.DrawRectangle(&Pen(Color::Black, 3), layoutRect);
}
Requirements
Requirement | Value |
---|---|
Header | gdiplusgraphics.h |