CListBox::SetTabStops

voidSetTabStops();

BOOLSetTabStops(constint&cxEachStop);

BOOLSetTabStops(intnTabStops**,LPINTrgTabStops);**

Return Value

Nonzero if all the tabs were set; otherwise 0.

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.

Remarks

Sets the tab-stop positions in a list box.

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

// The pointer to my list box.
extern CListBox* pmyListBox;

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

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

   sz = pDC->GetTextExtent(str);

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

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

CListBox OverviewClass MembersHierarchy Chart

See Also   ,