CComboBox::LimitText
在用户可以输入组合框的编辑控件文本的字节长度限制。
BOOL LimitText(
int nMaxChars
);
参数
- nMaxChars
指定长度(以字节用户可以输入的)的文本。 如果此参数是0,文本长度设置为65,535字节。
返回值
非零,如果成功。 如果调用为该样式的 CBS_DROPDOWNLIST 组合框或为组合框未编辑控件,则返回值是 CB_ERR。
备注
如果组合框没有该样式 CBS_AUTOHSCROLL,将文本限制大于编辑控件的大小将不起作用。
LimitText 只限制用户可以输入的文本。 它没有任何文本效果已在编辑控件,当发送时信息,也不影响该文本的长度复制到编辑控件,当在列表框中的字符串时。
示例
// 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);
要求
Header: afxwin.h