Graphics::MeasureString(constWCHAR*,INT,constFont*,constRectF&,constStringFormat*,RectF*,INT*,INT*) メソッド (gdiplusgraphics.h)

Graphics::MeasureString メソッドは、指定したフォント、書式、レイアウト四角形の文字列の範囲を測定します。

構文

Status MeasureString(
  const WCHAR        *string,
  INT                length,
  const Font         *font,
  const RectF &      layoutRect,
  const StringFormat *stringFormat,
  RectF              *boundingBox,
  INT                *codepointsFitted,
  INT                *linesFilled
);

パラメーター

string

測定するワイド文字列へのポインター。

大事な アラビア語などの双方向言語の場合、文字列の長さは 2046 文字を超えることはできません。

length

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

font

文字列に適用するフォントのファミリ名、サイズ、スタイルを指定する Font オブジェクトへのポインター。

layoutRect

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

stringFormat

配置、トリミング、タブ位置などのレイアウト情報を指定する StringFormat オブジェクトへのポインター。

boundingBox

文字列をバインドする四角形を受け取る RectF オブジェクトへのポインター。

codepointsFitted

省略可能。 レイアウトの四角形に実際に収まる文字数を受け取る INT へのポインター。 既定値は NULL ポインターです。

linesFilled

省略可能。 レイアウト四角形に収まる行数を受け取る INT へのポインター。 既定値は NULL ポインターです。

戻り値

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

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

解説

次の例では、文字列のサイズを測定し、そのサイズを表す四角形を描画します。

VOID Example_MeasureString2(HDC hdc)
{
   Graphics graphics(hdc);
   // Set up the string.
   WCHAR string[] = L"Measure Text";
   Font font(L"Arial", 16);
   RectF layoutRect(0.0f, 0.0f, 100.0f, 50.0f);
   StringFormat format;
   format.SetAlignment(StringAlignmentFar);
   RectF boundRect;
   // Measure the string.
   graphics.MeasureString(string, 12, &font, layoutRect, &format, &boundRect);
   // Draw a rectangle that represents the size of the string.
   graphics.DrawRectangle(&Pen(Color(255, 0, 0, 0)), boundRect);
}

要件

   
Header gdiplusgraphics.h

こちらもご覧ください

DrawString メソッド

フォント

グラフィックス

RectF

StringFormat