Default
Google

How can I add images to a ListBox?

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

 
 1.
  Start a new project using File | New Application.
 
 2.
  Add an ImageList. Insert two small bitmaps.
 
 3.
  Add a ListBox. Insert two items. Set the Style to lbOwnerDrawFixed.
      Double-click the OnDrawItem events:
 
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int
    Index, TRect &Rect, TOwnerDrawState State)
{
    ListBox1->Canvas->FillRect(Rect);
    ImageList1->Draw(ListBox1->Canvas, Rect.Left + 2, Rect.Top,
        Index, true);
 
    ListBox1->Canvas->TextOut(Rect.Left + ImageList1->Width + 4,
        Rect.Top, ListBox1->Items->Strings[Index]);
}

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



Acquiring image from ProHosting Banner Exchange