次の方法で共有


CEditView::SetTabStops

表示と印刷に使うタブ ストップを設定します。

void SetTabStops(
   int nTabStops 
);

パラメーター

  • nTabStops
    各タブ ストップの幅をダイアログ単位で指定します。

解説

タブ ストップの幅は 1 つだけサポートされます。 CEdit オブジェクトでは複数のタブ幅をサポートします。幅はダイアログ単位です。ダイアログ単位は、表示または印刷に使うフォントの平均文字幅の 1/4 です (英字の大文字と小文字のみを基準とします)。 CEditView はタブ ストップ値をキャッシュしているので、CEdit::SetTabStops を使わないでください。

この関数は呼び出されたオブジェクトのタブのみを変更します。 アプリケーションで各 CEditView オブジェクトのタブ ストップを変更するときは、各オブジェクトの SetTabStops 関数を呼び出します。

使用例

このコードはコントロールが使用するフォントを計測して、4 文字ごとにコントロールのタブ ストップを設定します。

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

必要条件

**ヘッダー:**afxext.h

参照

参照

CEditView クラス

階層図

CWnd::SetFont

CEditView::SetPrinterFont

その他の技術情報

CEditView のメンバー