您的位置:首页 > 其它

MFC 下拉框下拉条目宽高设置

2010-05-10 16:48 399 查看
有时候下拉框(MFC标准叫组合框,CComboBox)中条目文本很多,超过了下拉框的宽度,如果不加设置的话,超过的部分文本将无法显示,查找MSDN,发现解决方法,代码如下:

代码

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

// Set the height of every item so the item
// is completely visible.
CString str;
CSize   sz;
int     dx=0;
CDC*    pDC = pmyComboBox->GetDC();
for (int i=0;i < pmyComboBox->GetCount();i++)
{
pmyComboBox->GetLBText( i, str );
sz = pDC->GetTextExtent(str);

// Only want to set the item height if the current height
// is not big enough.
if (pmyComboBox->GetItemHeight(i) < sz.cy)
pmyComboBox->SetItemHeight( i, sz.cy );

// Only want to set the item width if the current width
// is not big enough.
if (pmyComboBox->GetDroppedWidth() < sz.cx)
{
pmyComboBox->SetDroppedWidth(sz.cx + 20);
}
}
pmyComboBox->ReleaseDC(pDC);


效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: