Share via


CListBox::SetTabStops

Sets the tab-stop positions in a list box.

void SetTabStops( ); 
BOOL SetTabStops( 
   const int& cxEachStop  
); 
BOOL SetTabStops( 
   int nTabStops, 
   LPINT rgTabStops  
);

Parameters

  • cxEachStop
    Tab stops are set at every cxEachStop dialog units. See rgTabStops for a description of a dialog unit.

  • nTabStops
    Specifies the number of tab stops to have in the list box.

  • rgTabStops
    Points to the first member of an array of integers containing the tab-stop positions in dialog units. A dialog unit is a horizontal or vertical distance. One horizontal dialog unit is equal to one-fourth of the current dialog base width unit, and one vertical dialog unit is equal to one-eighth of the current dialog base height unit. The dialog base units are computed based on the height and width of the current system font. The GetDialogBaseUnits Windows function returns the current dialog base units in pixels. The tab stops must be sorted in increasing order; back tabs are not allowed.

Return Value

Nonzero if all the tabs were set; otherwise 0.

Remarks

To set tab stops to the default size of 2 dialog units, call the parameterless version of this member function. To set tab stops to a size other than 2, call the version with the cxEachStop argument.

To set tab stops to an array of sizes, use the version with the rgTabStops and nTabStops arguments. A tab stop will be set for each value in rgTabStops, up to the number specified by nTabStops.

To respond to a call to the SetTabStops member function, the list box must have been created with the LBS_USETABSTOPS style.

Example

// Find the pixel width of the largest first substring.
CString str;
CSize   sz;
int     nIndex, dx = 0;
CDC*    pDC = myListBox.GetDC();
for (int i = 0; i < myListBox.GetCount(); i++)
{
   myListBox.GetText( i, str );

   if ((nIndex = str.Find('\t')) != -1)
      str = str.Right(nIndex);

   sz = pDC->GetTextExtent(str);

   if (sz.cx > dx)
      dx = sz.cx;
}
myListBox.ReleaseDC(pDC);

// Set tab stops at every one and 1/3 units 
// of the largest string.  
// NOTE: Convert pixels to dialog units.
myListBox.SetTabStops((dx*4/3 * 4) / LOWORD(::GetDialogBaseUnits()));

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

LB_SETTABSTOPS

GetDialogBaseUnits