没有用啊,你是说Horizontal scroll 这个属性吗? 选了啊,没用的!

解决方案 »

  1.   

    sorry,确实没用
    不选多行?
    没用的
      

  2.   

    ListBox是不能换行的。你可以长了以后加提示。
    VC知识库第10期有例子
      

  3.   

    Sorry,看错了。
    是不行的。
      

  4.   

    SetHorizontalExtent有用吗? 我试试?
      

  5.   

    哇,Cline(元元)的对
    设置一个很大的数就ok了
    SetHorizontalExtent(1000);
      

  6.   

    请你们告诉我如何设置贴子好嘛?
    Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  7.   

    beni():最好根據字串長度動態置,1000太大了吧.
      

  8.   

    呵呵,我试了一下,好像要字符串长度8倍以上才看得全
    估计大小字体还可能有影响
    CListBox也够笨的,不会自己算
      

  9.   

    自己程序中的一個片段:
    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);
    }主要是要在刪除時作全面調整,添加時,只要與其最寬比較一下就可以了.
      

  10.   

    你可以派生一个多行的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;}