CEditView::SetTabStops

voidSetTabStops(intnTabStops**);**

Parameters

nTabStops

Width of each tab stop, in dialog units.

Remarks

Call this function to set the tab stops used for display and printing. 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 pointer to the control
CEdit* pCtrl = (CEdit*) GetDlgItem(IDC_EDIT1);
ASSERT(pCtrl != NULL);

// get the font the control is using
CFont* pFont = pCtrl->GetFont();
TEXTMETRIC tm;

// get the control's DC, too
CDC* pDC = pCtrl->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);

// Retreive 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(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.

pCtrl->SetTabStops((4 * tm.tmAveCharWidth * 100) / rect.Width());

CEditView OverviewClass MembersHierarchy Chart

See Also   CWnd::SetFont, CEditView::SetPrinterFont