请教在BCB中如何对TListBox中的每一项设置颜色

请问在BCB中怎么对TListBox中的每一项设置颜色
请问在BCB中怎么对TListBox中的每一项设置颜色

------解决方案--------------------
首先设置ListBox的Style为lbOwnerDrawFixed或lbOwnerDrawVariable,两种风格都可以进行自画,区别在于前者的风格是每一行的高度是固定的(由ItemHeight决定),而后者则可以指定某行的高度。

然后在ListBox的OnDrawItem事件中进行自画:
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
TListBox *lbx = (TListBox *)Control;
if(lbx == NULL) return;
if(Index == 1) // 设置第二项的颜色为蓝色
lbx-> Canvas-> Font-> Color = clBlue;
else
lbx-> Canvas-> Font-> Color = clBlack;
// 绘制出文本
lbx-> Canvas-> TextRect(Rect, 1, Rect.Top + 1, lbx-> Items-> Strings[Index]);
}

以上是一个最简单的例子