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?
-

-
- Start a new project using File | New Application.
-
- Add a ListBox. Insert items that exceed the visible area.
-
- 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