Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box not scrolling 1

Status
Not open for further replies.

dds82

Programmer
Joined
Jun 5, 2002
Messages
251
Location
US
I have a CListBox inside a CDialog. Both the "horizontal scroll" and "vertical scroll" flags on the list box are set (I did that in the resource editor), but I never get a horizontal scroll bar, though the vertical one works fine. Anybody know why?

Thanks.
 
Hi

It's not sufficient to set the listbox style. You also have to call the function SetHorizontalExtent and pass to it the maximum width of the strings of the listbox.
If this max. width is greater than the width of the list box, the scrollbar will be displayed.

As an example, here is the kind of code you can use. I declare the listbox with ClassWizard as m_List. I add some stupid strings with different width for the demo ...

CSize sizeText;
CString str;

CDC* pdc = m_List.GetWindowDC();
CFont* pFont = m_List.GetFont();
CFont* pOldFont = pdc->SelectObject( pFont);

for ( int x = 1; x < 30; x++)
{
sizeText = pdc->GetTextExtent( str);
m_List.SetHorizontalExtent( sizeText.cx + 10);

str.Format( &quot;This is string %ld and it's larger than the listbox&quot;, x*x*x*x);

m_List.AddString( str);
}

pdc->SelectObject( pOldFont);
ReleaseDC( pdc);

HTH

Thierry
EMail: Thierry.Marneffe@swing.be
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top