ListBox with bitmaps within the items  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 16/08/20

Tip accessed 518 times

 


We will use a TImageList to store the images of each Item.

  • Put a TImageList (ImageList1) and a TListBox (ListBox1) in your form
  • Put the Style property of ListBox1 to lbOwnerDrawFixed
  • Put the next code in their OnDrawItem event:


     procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
       Rect: TRect; State: TOwnerDrawState);
     begin
       with (Control as TListBox) do
       begin
         Canvas.FillRect(Rect);
         Canvas.TextOut(Rect.Left+ImageList1.Height+2,Rect.Top,Items[Index]);
         ImageList1.Draw(Canvas,Rect.Left,Rect.Top,Index);
       end;
     end;
    



    Ah!, this tip also is valid for a ComboBox...