Color item in a listbox

Quote
> "Louis Somers" <mlsom...@angelfire.com> wrote in message
>news:3995DB4D.2610F210@angelfire.com...
> I want to color items (strings) in a listbox that have been previously

selected, so the user knows

Quote
> 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);
begin
with ListBox1.Canvas do
     begin
     Font.Assign (ListBox1.Font);
     if odFocused in State
     then begin
          Brush.Color := clHighlight;
          Font.Color := clHighlightText;
          end
     else begin
          Brush.Color := ListBox1.Color;
          if odSelected in State
          then Font.Color := clBlue // or whatever color you want
          else Font.Color := clWindowText;
          end;
     FillRect (Rect);
     TextOut (Rect.Left, Rect.Top, ListBox1.Items [Index]);
     end;
end;