I need to add a Horizontal Scrollbar in a List box.
How do that?
Thanks
Printable View
I need to add a Horizontal Scrollbar in a List box.
How do that?
Thanks
Right click on the control, select properties and under the styles tab, select horizontal scroll
Regards
OR:
You can use the SendMessage API function to add a horizontal scroll bar dynamically to a list box using the LB_SETHORIZONTALEXTENT message.
Thanks at all. I find and solved my problem with this code....
// Find the longest string in the list box.
CListBox* pmyListBox = (CListBox *)GetDlgItem(IDC_LIST1);
CString str;
CSize sz;
int dx = 0;
TEXTMETRIC tm;
CDC* pDC = pmyListBox->GetDC();
CFont* pFont = pmyListBox->GetFont();
// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);
for (i = 0; i < pmyListBox->GetCount(); i++)
{
pmyListBox->GetText(i, str);
sz = pDC->GetTextExtent(str);
// Add the avg width to prevent clipping
sz.cx += tm.tmAveCharWidth;
if (sz.cx > dx)
dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
pmyListBox->ReleaseDC(pDC);
// Set the horizontal extent so every character of all strings
// can be scrolled to.
pmyListBox->SetHorizontalExtent(dx);
You are welcome dude.. and please use : Code tagsQuote:
Originally Posted by Antonio2929