Share via


Graphics::D rawString (constWCHAR*,INT,constFont*,constPointF&,constStringFormat*,constBrush*) 方法 (gdiplusgraphics.h)

Graphics::D rawString 方法會根據字型、字串原點和格式來繪製字串。

語法

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

參數

[in] string

類型: const WCHAR*

要繪製之寬字元字串的指標。

[in] length

類型: INT

指定 字串 陣列中字元數的整數。 如果字串為 Null 終止,則 length 參數可以設定為 –1。

[in] font

類型: const Font*

Font 物件的指標,指定字型屬性 (系列名稱、大小,以及要使用的字型樣式) 。

[in, ref] origin

類型: const PointF

PointF 對象的參考,指定字串的起點。

[in] stringFormat

類型: const StringFormat*

StringFormat 物件的指標,指定要套用至字串的文字配置資訊和顯示操作。

[in] brush

類型: const Brush*

用於填滿字串之 Brush 物件的指標。

傳回值

類型: 狀態

如果方法成功,它會傳回Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其他其中一個專案。

備註

請注意,GDI+ 不支援 PostScript 字型或沒有 TrueType 外框的 OpenType 字型。

當您使用 GDI+ API 時,不得允許應用程式從不受信任的來源下載任意字型。 操作系統需要較高的許可權,以確保所有已安裝的字型都受信任。

範例

下列範例會使用指定的格式,在指定的原點繪製字串。

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

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限桌面應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 gdiplusgraphics.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

字型

圖形

PointF

StringFormat