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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With