CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    72

    How add a horizontal scrollbar in ListBox?

    I need to add a Horizontal Scrollbar in a List box.
    How do that?

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    London, England
    Posts
    563

    Re: How add a horizontal scrollbar in ListBox?

    Right click on the control, select properties and under the styles tab, select horizontal scroll

    Regards
    I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)

  3. #3
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: How add a horizontal scrollbar in ListBox?

    OR:

    You can use the SendMessage API function to add a horizontal scroll bar dynamically to a list box using the LB_SETHORIZONTALEXTENT message.
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

  4. #4
    Join Date
    Dec 2003
    Posts
    72

    Re: How add a horizontal scrollbar in ListBox?

    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);

  5. #5
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: How add a horizontal scrollbar in ListBox?

    Quote Originally Posted by Antonio2929
    Thanks at all. I find and solved my problem with this code....
    // 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 tags
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured