【问题标题】:How to avoid CListCtrl items to be partially visible?如何避免 CListCtrl 项目部分可见?
【发布时间】:2010-11-30 11:28:48
【问题描述】:

我有一个可调整大小的 CListCtrl,我想避免任何项目被部分显示。

例如:

我希望在这种情况下不显示第 9 项。有没有一个标志或方法?您将如何解决这个问题?

我尝试了以下方法,但效果不佳:

void CMyCListCtrl::OnEndScrolling()
{
    int iCount = this->GetCountPerPage();
    EnsureVisible(iCount - 1, FALSE);
}

抓到后

...

ON_NOTIFY( LVN_ENDSCROLL, IDC_LIST1, OnEndScroll )

...

   void CWheelTestDlg::OnEndScroll(NMHDR* pNMHDR, LRESULT* pResult)
   {
       LPNMLVSCROLL pnmLVScroll = (LPNMLVSCROLL) pNMHDR;

       m_MyListCtrl.OnEndScrolling();
       *pResult = 0;
   }

在 CListCtrl 父对话框中。 (我不想这样做,如果可能的话,我只想在我的 CListCtrl 派生类中做所有事情)。

我所做的只是完全显示第 9 项,但第 10 项在其下方部分可见。如果我有 30 项,我不想滚动列表以显示第 30 项,我想显示到第 8 项,而其下方没有部分可见的项。

【问题讨论】:

    标签: visual-c++ mfc clistctrl


    【解决方案1】:

    CListCtrl 似乎不支持积分高度。 这是一个通过强制更改控制高度[带有注释条件] (http://www.codeproject.com/Messages/418084/Socket-accept-call.aspx) 来实现您想要的解决方案:

    /////////////////////////////////////////////////////////////////////////////////
    // This assumes a REPORT-style CListCtrl.
    //
    // Resize the control. This works correctly only if scrolling is disabled. If
    // there is scrolling, then setting to the size from ApproximateViewRect() will
    // always give scroll bars showing. Which is irritating.
    //
    // We need to adjust the vertical size from what ApproximateViewRect() returns
    // by one row minus border width
    //////////////////////////////////////////////////////////////////////////////////
    CSize sz = m_list.ApproximateViewRect();    // always adds room for a new row
    
    CRect itRect;   // Get the height of a single row (there had better *be* a row!)
    m_list.GetItemRect(0, &itRect, LVIR_BOUNDS);
    
    int vOffset = itRect.Height() - 3;  // leave a little 'cuz it looks better
    m_list.SetWindowPos(NULL, 0, 0, sz.cx, sz.cy - vOffset,
        SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE);
    

    【讨论】:

      【解决方案2】:

      我在wince中遇到了类似的问题,偶然找到了解决方案。互联网上没有直接的解决方案,所以我决定在收到一些消息后重新定位滚动条,我在wince中唯一可以使用的消息是WM_LBUTTONDOWN,其他消息如OnEndScroll没有被调用,可能是我的问题代码。

      不管怎样,我用Timer(ON_WM_TIMER)在收到WM_LBUTTONDOWN消息时重新定位滚动条,然后发现列表控件没有自动滚动!然后我保持一个空的 OnTimer 函数并删除其他所有内容。它有效,我猜列表控件使用 Timer 滚动部分行。

      希望对你有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 2021-05-24
        • 1970-01-01
        相关资源
        最近更新 更多