实际应用中,ComboBox的下拉框的长度默认是和它的Edit框相同的,如果插入的个别项特别长时会显示不全。
解决方法如下:
CString str;
int dx = 0;
CSize sz;
CDC *pDC = m_CobName.GetDC();
CFont *pOldFont = pDC->SelectObject(m_CobName.GetFont());
for (int i = 0; i < m_CobName.GetCount(); i++)
{
m_CobName.GetLBText(i, str);
sz = pDC->GetTextExtent(str);
if (sz.cx > dx)
{
dx = sz.cx;
}
}
m_CobName.SetDroppedWidth(dx+30);
pDC->SelectObject(pOldFont);
m_CobName.ReleaseDC(pDC);