Colour or formatting in a Delphi List Box (TListBox)

Is it possible to apply some basic formatting (bold, colour) to one entry in a list box rather than apply formatting to all items in the list box.

If not, what would be a good component to achive:
BOLD TEXT [heading]
GREEN TEXT [sub heading]
NORMAL TEXT [regular data]

Thanks
SF
sheepfarmerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
btframeworkConnect With a Mentor Commented:
There is the demo in Demos folder called Ownerlist which shows exactly you want to do.
(ListBox1 has OwnerDraw property set to true)
procedure TForm1.DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with ListBox1.Canvas do
  begin
    FillRect(Rect);
    Font.Name := ListBox1.Items[Index];
    Font.Size := 0;    // use font's preferred size
    TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[Index]);
  end;
end;
 
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
begin
  with ListBox1.Canvas do
  begin
    Font.Name := Listbox1.Items[Index];
    Font.Size := 0;                 // use font's preferred size
    Height := TextHeight('Wg') + 2; // measure ascenders and descenders
  end;
end;

Open in new window

0
 
sheepfarmerAuthor Commented:
Thanks - will check it out and report back.
0
 
sheepfarmerAuthor Commented:
Not tried yet, but it looks reasonabe.  Thanks for your help
0
All Courses

From novice to tech pro — start learning today.