Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal scroll not coming for listbox?

Tags:

mfc

I am having a listbox where I set both the properties i.e, vertical and horizontal scroll to true.I am able to get vertical scroll bar but not able to get horizontal scroll bar when added a lengthy string.

Can anyone please let me know how get horizontal scroll bar for a listbox.

like image 900
Siva Avatar asked Oct 16 '25 19:10

Siva


1 Answers

Adding this piece of code in OnInitDialog resolved my issue.

BOOL OnInitDialog()
{
  CString str;
    CSize sz;
    int dx = 0;
    CDC* pDC = m_listbox.GetDC();
    for(int i=0; i < m_listbox.GetCount();i++)
    {
        m_listbox.GetText(i,str);
        sz = pDC->GetTextExtent(str);

        if(sz.cx > dx)
            dx = sz.cx;

    }
    m_listbox.ReleaseDC(pDC);

    if(m_listbox.GetHorizontalExtent() < dx )
    {
        m_listbox.SetHorizontalExtent(dx);
        ASSERT(m_listbox.GetHorizontalExtent() == dx);

    }

  return TRUE;
}
like image 149
Siva Avatar answered Oct 19 '25 15:10

Siva