StringFormat::SetTabStops 方法 (gdiplusstringformat.h)

StringFormat::SetTabStops方法會設定此StringFormat物件中定位停駐點的位移。

語法

Status SetTabStops(
  [in] REAL       firstTabOffset,
  [in] INT        count,
  [in] const REAL *tabStops
);

參數

[in] firstTabOffset

類型: REAL

指定初始位移位置的實數。 這個初始位移位置相對於字串的原點,而第一個定位停駐點的位移相對於初始位移位置。

[in] count

類型: INT

整數,指定 tabStops 陣列中的定位停駐點位移數目。

[in] tabStops

類型: const REAL*

指定制表位位位移之實數陣列的指標。 第一個定位停駐點的位移是陣列中的第一個值、第二個定位停駐點位的位移、陣列中的第二個值等等。

傳回值

類型: 狀態

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

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

備註

tabStops陣列中的每個定位停駐點位移,但第一個位移除外,與前一個位移相對。 第一個定位停駐點位移相對於 firstTabOffset所指定的初始位移位置。 例如,如果初始位移位置為 8,而第一個定位停駐點位移為 50,則第一個定位停駐點點位於位置 58。 如果初始位移位置為零,則第一個定位停駐點位移相對於位置 0,即字串原點。

範例

下列範例會建立 StringFormat 物件、設定制表位,並使用 StringFormat 物件繪製包含索引標籤字元的字串, (\t) 。 程式碼也會繪製字串的配置矩形。

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

   REAL         tabs[] = {150, 100, 100};
   FontFamily   fontFamily(L"Courier New");
   Font         font(&fontFamily, 12, FontStyleRegular, UnitPoint);
   SolidBrush   solidBrush(Color(255, 0, 0, 255));

   StringFormat stringFormat;
   stringFormat.SetTabStops(0, 3, tabs);
   graphics.DrawString(
      L"Name\tTest 1\tTest 2\tTest 3", 
      25, 
      &font, 
      RectF(20, 20, 500, 100), 
      &stringFormat, 
      &solidBrush);

   // Draw the rectangle that encloses the text.
   Pen pen(Color(255, 255, 0, 0));
   graphics.DrawRectangle(&pen, 20, 20, 500, 100);
}

需求

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

另請參閱

設定文字格式

StringFormat

StringFormat::GetTabStops