Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Colors in TListBox

Status
Not open for further replies.

Spent

Programmer
Mar 20, 2003
100
BG
Is it possible to have a TListBox on which different lines to have a different color for example:
line1 // red color
line2 // green color

Thanks !

Spent
mail:spentbg@yahoo.com
 
Set the Style property of your listbox to
Code:
lbOwnerDrawFixed
.

Write an OnDrawItem event handler along the lines of:
Code:
[COLOR=blue]
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
 Rect: TRect; State: TOwnerDrawState);
begin
 case index of
  0: ListBox1.Canvas.Brush.Color := clRed;
  1: ListBox1.Canvas.Brush.Color := clBlue;
  2: ListBox1.Canvas.Brush.Color := clGreen;
  3: ListBox1.Canvas.Brush.Color := clAqua;
 end;
 ListBox1.Canvas.TextRect(rect,rect.Left,rect.Top,ListBox1.Items[index]);
end;
[/color]

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top