共用方式為


CComboBox::LimitText

Limits the length in bytes of the text that the user can enter into the edit control of a combo box.

BOOL LimitText( 
   int nMaxChars  
);

Parameters

  • nMaxChars
    Specifies the length (in bytes) of the text that the user can enter. If this parameter is 0, the text length is set to 65,535 bytes.

Return Value

Nonzero if successful. If called for a combo box with the style CBS_DROPDOWNLIST or for a combo box without an edit control, the return value is CB_ERR.

Remarks

If the combo box does not have the style CBS_AUTOHSCROLL, setting the text limit to be larger than the size of the edit control will have no effect.

LimitText only limits the text the user can enter. It has no effect on any text already in the edit control when the message is sent, nor does it affect the length of the text copied to the edit control when a string in the list box is selected.

Example

// Limit the number of characters in the combo box's edit control to 
// be the maximum number visible. 

// Get the text metrics for the combo box; needed for the 
// average character width.
TEXTMETRIC tm;
CDC* pDCCB = m_pComboBox->GetDC();
pDCCB->GetTextMetrics(&tm);
m_pComboBox->ReleaseDC(pDCCB);

CRect rect;
m_pComboBox->GetClientRect(&rect);

m_pComboBox->LimitText(rect.Width() / tm.tmAveCharWidth);

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CB_LIMITTEXT