Default
Google

How can I add a horizontal scroll bar?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

My ListBox contains some very long items. I don't want to change its size so is it possible to add a horizontal scroll bar to my ListBox?
 
 
 1.
  Start a new project using File | New Application.
 
 2.
  Add a ListBox. Insert items that exceed the visible area.
 
 3.
  Edit the OnCreate event of your form:
 
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    int width = 0;
    for(int x = 0; x < ListBox1->Items->Count; x++)
    {
        int text = ListBox1->Canvas->TextWidth(ListBox1->
            Items->Strings[x]);
        if(text > width)
            width = text;
    }
    ListBox1->Perform(LB_SETHORIZONTALEXTENT, width, 0);
}

C++Builder Developer's Network
Copyright © Yoto Yotov



Acquiring image from ProHosting Banner Exchange