StringFormat::GetTabStops 方法 (gdiplusstringformat.h)
StringFormat::GetTabStops方法會取得這個StringFormat物件中定位停駐點的位移。
語法
Status GetTabStops(
[in] INT count,
[out] REAL *firstTabOffset,
[out] REAL *tabStops
);
參數
[in] count
類型: INT
整數,指定 tabStops 陣列中的定位停駐點位移數目。
[out] firstTabOffset
類型: REAL*
接收初始位移位置 之 REAL 的指標。 這個初始位移位置相對於字串的原點,而第一個定位停駐點的位移相對於初始位移位置。
[out] tabStops
類型: REAL*
實數值型別的陣列指標,該陣列會接收定位停駐點位移。 第一個定位停駐點的位移是陣列中的第一個值、第二個定位停駐點位的位移、陣列中的第二個值等等。
傳回值
類型: 狀態
如果方法成功,它會傳回 Ok,這是 Status 列舉的元素。
如果方法失敗,它會傳回 Status 列舉的其中一個其他元素。
備註
tabStops陣列中的每個定位停駐點位移,但第一個位移除外,與前一個位移相對。 第一個定位停駐點位移相對於 firstTabOffset所指示的初始位移位置。 例如,如果初始位移位置為 8,而第一個定位停駐點位移為 50,則第一個定位停駐點點位於位置 58。 如果初始位移位置為零,則第一個定位停駐點位移相對於位置 0,即字串原點。
範例
下列範例會建立 StringFormat 物件、設定制表位,並使用 StringFormat 物件繪製包含索引標籤字元的字串, (\t) 。 程式碼也會繪製字串的配置矩形。 然後,程式碼會取得定位停駐點,並繼續以某種方式使用或檢查定位停駐點。
VOID Example_GetTabStop(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);
// Get the tab stops.
INT tabStopCount = 0;
REAL firstTabOffset = 0;
REAL* tabStops = NULL;
tabStopCount = stringFormat.GetTabStopCount();
tabStops = (REAL*)malloc(tabStopCount*sizeof(REAL));
stringFormat.GetTabStops(tabStopCount, &firstTabOffset, tabStops);
for(INT j = 0; j < tabStopCount; ++j)
{
// Inspect or use the value in tabStops[j].
}
}
需求
最低支援的用戶端 | Windows XP、Windows 2000 Professional [僅限傳統型應用程式] |
最低支援的伺服器 | Windows 2000 Server [僅限傳統型應用程式] |
目標平台 | Windows |
標頭 | gdiplusstringformat.h (包含 Gdiplus.h) |
程式庫 | Gdiplus.lib |
Dll | Gdiplus.dll |