CEditView::SetTabStops

调用此函数设置用于显示和打印的制表位。

void SetTabStops(
   int nTabStops 
);

参数

  • nTabStops
    每个制表位的宽度,对话框单位。

备注

只有一个制表位宽度支持。(CEdit 对象支持多个选项卡宽度。)宽度在对话框单位,等于平均字符宽度的四分之一(仅根据大写和小写字母字符在字符串中显示时使用的)的字体。因为 CEditView 必须缓存制表位值,不应使用 CEdit::SetTabStops

此功能修改它调用对象中可用的选项。若要更改每 CEditView 对象的制表位在应用程序中,调用每个对象的 SetTabStops 功能。

示例

此代码片段设置控件的制表位对于每第四个字符仔细度量控件使用的字体。

// gain a reference to the edit control
CEdit& theEdit = GetEditCtrl();

// get the font the control is using
CFont* pFont = theEdit.GetFont();
TEXTMETRIC tm;

// get the control's DC, too
CDC* pDC = theEdit.GetDC();

// Select the font that the control uses by default into the DC.
// We must do this because the control may or may not be using
// that font at this exact moment
CFont* pOldFont = pDC->SelectObject(pFont);

// Retrieve text metrics for that font and return the previously
// selected font.
pDC->GetTextMetrics(&tm);
pDC->SelectObject(pOldFont);

// Get an identity rectangle and map it to dialog units
CRect rect(0, 0, 100, 1);
::MapDialogRect((HWND)this, rect);

// We now know that 100 dialog units are rect.Width() screen units,
// so we can multiply screen units by 100 and divide by rect.Width()
// to find dialog units from screen units. tm.tmAveCharWidth is
// the width of _one_ character, so setting the tabs at every
// four characters means we also multiply by four.
SetTabStops((4 * tm.tmAveCharWidth * 100) / rect.Width());

要求

Header: afxext.h

请参见

参考

CEditView选件类

层次结构图

启动

CEditView::SetPrinterFont