ListBox不能换行吗?那我怎么办? 没有用啊,你是说Horizontal scroll 这个属性吗? 选了啊,没用的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sorry,确实没用不选多行?没用的 ListBox是不能换行的。你可以长了以后加提示。VC知识库第10期有例子 Sorry,看错了。是不行的。 SetHorizontalExtent有用吗? 我试试? 哇,Cline(元元)的对设置一个很大的数就ok了SetHorizontalExtent(1000); 请你们告诉我如何设置贴子好嘛?Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! beni():最好根據字串長度動態置,1000太大了吧. 呵呵,我试了一下,好像要字符串长度8倍以上才看得全估计大小字体还可能有影响CListBox也够笨的,不会自己算 自己程序中的一個片段:void CDictDlg::JustifyHorzExtLen(){ CSize WordSize; CDC* pDC=this->m_CtrlListBox.GetDC (); CFont NewFont; CFont* pOldFont=NULL; NewFont.CreateFontIndirect (&lfFont ); pOldFont=pDC->SelectObject (&NewFont ); int nCount=this->m_CtrlListBox.GetCount (); m_nHorzExtLen =0; CString csText; //計算最大寬度 for(int i=0;i<nCount;i++) { csText.Empty (); m_CtrlListBox.GetText (i,csText); WordSize=pDC->GetTextExtent (csText); if(WordSize.cx >m_nHorzExtLen ) m_nHorzExtLen =WordSize.cx ; } //設置水平最大寬度 m_CtrlListBox.SetHorizontalExtent (m_nHorzExtLen+1); pDC->SelectObject (pOldFont);}主要是要在刪除時作全面調整,添加時,只要與其最寬比較一下就可以了. 你可以派生一个多行的CListBox.这样也是一个办法。继承的方法是:计算宽度是否超越LIST的宽,如果是就加大每一列的高度,高度的设置要根据加入的具体的文字的大小来设置,然后就在:void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 的函数下添加包含下列的代码(注意,只是一部分,但也是最重要的,特别是最后几句,相应的变量相信你可以判断出来,虽然我没有说) if (!(lpDrawItemStruct->itemState & ODS_SELECTED)) { CRect rect = lpDrawItemStruct->rcItem; CBrush brush(rColor); pDC->SetBkColor(rColor); pDC->FillRect(&rect,&brush); pDC->DrawText( sLabel,&lpDrawItemStruct->rcItem, DT_WORDBREAK );//非常 重要的一句。 return; }完整的例子见下面:void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); COLORREF rColor = (COLORREF)lpDrawItemStruct->itemData; //你可以不用把数据放在MEASUREITEMSTRUCT的itemData变量中,在下面的CBrush直接构造也可以的。 CString sLabel; GetText(lpDrawItemStruct->itemID, sLabel); // item selected if ((lpDrawItemStruct->itemState & ODS_SELECTED)) { // draw color box CBrush colorBrush(rColor); CRect colorRect = lpDrawItemStruct->rcItem; // draw label background CBrush labelBrush(::GetSysColor(COLOR_HIGHLIGHT)); CRect labelRect = lpDrawItemStruct->rcItem; pDC->FillRect(&labelRect,&labelBrush); // draw label text COLORREF colorTextSave; COLORREF colorBkSave; colorBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); pDC->DrawText( sLabel, &lpDrawItemStruct->rcItem, DT_WORDBREAK ); colorTextSave = pDC->SetTextColor(::GetSysColor(COLOR_INFOBK)); pDC->SetTextColor(colorTextSave); pDC->SetBkColor(colorBkSave); return; } // item deselected if (!(lpDrawItemStruct->itemState & ODS_SELECTED)) { CRect rect = lpDrawItemStruct->rcItem; CBrush brush(rColor); pDC->SetBkColor(rColor); pDC->FillRect(&rect,&brush); pDC->DrawText( sLabel,&lpDrawItemStruct->rcItem, DT_WORDBREAK ); return; }}void CMultiLineListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {// all items are of fixed size// must use LBS_OWNERDRAWVARIABLE for this to work int nItem = lpMeasureItemStruct->itemID; CPaintDC dc(this); CString sLabel; CRect rcLabel; GetText( nItem, sLabel ); GetItemRect(nItem, rcLabel);//下面把高度设置为具体的高度。具体高度由DrawText返回。 int itemHeight = dc.DrawText( sLabel, rcLabel, DT_WORDBREAK | DT_CALCRECT ); lpMeasureItemStruct->itemHeight = itemHeight;} !m_pRecordset->adoEOF和!m_pInputRecordset->BOF都不起作用,帮忙解决 Playing wav 一个对话框的问题 在vckbase上下载的代码怎么打开?希望赐教 窗口间控件的操作? ★前辈给点建议:刚工作的VC程序员月薪大概是多少?★ 请教如何做按钮的提示信息? CryptoAPI测试问题 双向队列添加CBitmap时报错 给视图添加消息映射的一个问题 WM_SETCURSOR什么时候触发?谁能详细说一下? 怎么获得cpu的频率?inter的和amd的都要
不选多行?
没用的
VC知识库第10期有例子
是不行的。
设置一个很大的数就ok了
SetHorizontalExtent(1000);
Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
估计大小字体还可能有影响
CListBox也够笨的,不会自己算
void CDictDlg::JustifyHorzExtLen()
{
CSize WordSize;
CDC* pDC=this->m_CtrlListBox.GetDC ();
CFont NewFont;
CFont* pOldFont=NULL;
NewFont.CreateFontIndirect (&lfFont );
pOldFont=pDC->SelectObject (&NewFont );
int nCount=this->m_CtrlListBox.GetCount ();
m_nHorzExtLen =0;
CString csText; //計算最大寬度
for(int i=0;i<nCount;i++)
{
csText.Empty ();
m_CtrlListBox.GetText (i,csText);
WordSize=pDC->GetTextExtent (csText);
if(WordSize.cx >m_nHorzExtLen )
m_nHorzExtLen =WordSize.cx ; } //設置水平最大寬度
m_CtrlListBox.SetHorizontalExtent (m_nHorzExtLen+1);
pDC->SelectObject (pOldFont);
}主要是要在刪除時作全面調整,添加時,只要與其最寬比較一下就可以了.
void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
的函数下添加包含下列的代码(注意,只是一部分,但也是最重要的,特别是最后几句,相应的变量相信你可以判断出来,虽然我没有说)
if (!(lpDrawItemStruct->itemState & ODS_SELECTED))
{
CRect rect = lpDrawItemStruct->rcItem;
CBrush brush(rColor);
pDC->SetBkColor(rColor);
pDC->FillRect(&rect,&brush);
pDC->DrawText( sLabel,&lpDrawItemStruct->rcItem, DT_WORDBREAK );//非常 重要的一句。 return;
}
完整的例子见下面:void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); COLORREF rColor = (COLORREF)lpDrawItemStruct->itemData;
//你可以不用把数据放在MEASUREITEMSTRUCT的itemData变量中,在下面的CBrush直接构造也可以的。
CString sLabel;
GetText(lpDrawItemStruct->itemID, sLabel); // item selected
if ((lpDrawItemStruct->itemState & ODS_SELECTED))
{
// draw color box
CBrush colorBrush(rColor);
CRect colorRect = lpDrawItemStruct->rcItem; // draw label background
CBrush labelBrush(::GetSysColor(COLOR_HIGHLIGHT));
CRect labelRect = lpDrawItemStruct->rcItem;
pDC->FillRect(&labelRect,&labelBrush); // draw label text
COLORREF colorTextSave;
COLORREF colorBkSave; colorBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC->DrawText( sLabel, &lpDrawItemStruct->rcItem, DT_WORDBREAK );
colorTextSave = pDC->SetTextColor(::GetSysColor(COLOR_INFOBK)); pDC->SetTextColor(colorTextSave);
pDC->SetBkColor(colorBkSave); return;
} // item deselected
if (!(lpDrawItemStruct->itemState & ODS_SELECTED))
{
CRect rect = lpDrawItemStruct->rcItem;
CBrush brush(rColor);
pDC->SetBkColor(rColor);
pDC->FillRect(&rect,&brush);
pDC->DrawText( sLabel,&lpDrawItemStruct->rcItem, DT_WORDBREAK ); return;
}}void CMultiLineListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// all items are of fixed size
// must use LBS_OWNERDRAWVARIABLE for this to work int nItem = lpMeasureItemStruct->itemID;
CPaintDC dc(this);
CString sLabel;
CRect rcLabel; GetText( nItem, sLabel );
GetItemRect(nItem, rcLabel);
//下面把高度设置为具体的高度。具体高度由DrawText返回。 int itemHeight = dc.DrawText( sLabel, rcLabel, DT_WORDBREAK | DT_CALCRECT );
lpMeasureItemStruct->itemHeight = itemHeight;}