Graphics::D rawString(constWCHAR*,INT,constFont*,constRectF&,constStringFormat*,constBrush*) メソッド (gdiplusgraphics.h)

Graphics::D rawString メソッドは、フォント、レイアウト四角形、および書式に基づいて文字列を描画します。

構文

Status DrawString(
  const WCHAR        *string,
  INT                length,
  const Font         *font,
  const RectF &      layoutRect,
  const StringFormat *stringFormat,
  const Brush        *brush
);

パラメーター

string

描画するワイド文字列へのポインター。

length

文字列配列内の文字数を指定する整数。 文字列が null で終わる場合は、 length パラメーターを -1 に設定できます。

font

使用するフォント属性 (ファミリ名、サイズ、フォントのスタイル) を指定する Font オブジェクトへのポインター。

layoutRect

文字列を囲む四角形への参照。

stringFormat

文字列に適用するテキスト レイアウト情報と表示操作を指定する StringFormat オブジェクトへのポインター。

brush

文字列の塗りつぶしに使用される Brush オブジェクトへのポインター。

戻り値

メソッドが成功した場合は、Status 列挙体の要素である Ok を返します

メソッドが失敗した場合は、 Status 列挙体の他の要素のいずれかを返します。

注釈

GDI+ では、TrueType アウトラインのない PostScript フォントまたは OpenType フォントはサポートされないことに注意してください。

GDI+ API を使用する場合、アプリケーションで信頼されていないソースから任意のフォントをダウンロードできないようにする必要があります。 オペレーティング システムでは、インストールされているすべてのフォントが信頼されるように、昇格された特権が必要です。

次の例では、指定した書式を使用して、レイアウト四角形に文字列を描画します。

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);
}

要件

   
Header gdiplusgraphics.h

こちらもご覧ください

グラフィックス

フォント

ペン

RectF

StringFormat