Color item in a listbox

> "Louis Somers" <> wrote in message
> I want to color items (strings) in a listbox that have been previously

selected, so the user knows

> which ones he already had selected before.
> Is there any way to do something like this:
> ListBox1.Items.Objects[x].font.color := clBlue;
> Objects[x].font  wont work nither will Strings[x].font
> Coloring the background would also do but also this, I wouldn't know how
to accomplish it.
> Thanks alot

Set the list box's style to lbOwnerDrawFixed and write an OnDrawItem event
handler to paint the selections., something like:

procedure TForm1.ListBox1DrawItem
                        (Control : tWinControl;
                         Index : Integer;
                         Rect : TRect;
                         State: TOwnerDrawState);
with ListBox1.Canvas do
     Font.Assign (ListBox1.Font);
     if odFocused in State
     then begin
          Brush.Color := clHighlight;
          Font.Color := clHighlightText;
     else begin
          Brush.Color := ListBox1.Color;
          if odSelected in State
          then Font.Color := clBlue // or whatever color you want
          else Font.Color := clWindowText;
     FillRect (Rect);
     TextOut (Rect.Left, Rect.Top, ListBox1.Items [Index]);