Condividi tramite


CEditView::SetTabStops

Call this function to set the tab stops used for display and printing.

void SetTabStops(
   int nTabStops 
);

Parameters

  • nTabStops
    Width of each tab stop, in dialog units.

Remarks

Only a single tab-stop width is supported. (CEdit objects support multiple tab widths.) Widths are in dialog units, which equal one-fourth of the average character width (based on uppercase and lowercase alphabetic characters only) of the font used at the time of printing or displaying. You should not use CEdit::SetTabStops because CEditView must cache the tab-stop value.

This function modifies only the tabs of the object for which it is called. To change the tab stops for each CEditView object in your application, call each object's SetTabStops function.

Example

This code fragment sets the tab stops in the control to every fourth character by carefully measuring the font the control uses.

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

Requirements

Header: afxext.h

See Also

Reference

CEditView Class

Hierarchy Chart

CWnd::SetFont

CEditView::SetPrinterFont

Other Resources

CEditView Members