StringFormat::SetTabStops 方法 (gdiplusstringformat.h)

StringFormat::SetTabStops 方法设置此 StringFormat 对象中制表位的偏移量。

语法

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

parameters

[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)
Library Gdiplus.lib
DLL Gdiplus.dll

另请参阅

设置文本格式

StringFormat

StringFormat::GetTabStops