BCB-修改ListBox 的字體顏色
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,TRect &Rect, TOwnerDrawState State)
{
if(State.Contains(odSelected)){
ListBox1->Canvas->Brush->Color = clBlue;
ListBox1->Canvas->Font->Color = clYellow;
}else{
ListBox1->Canvas->Brush->Color = clWhite;
ListBox1->Canvas->Font->Color = clBlack;
}
ListBox1->Canvas->FillRect(Rect);
ListBox1->Canvas->TextOut(Rect.Left, Rect.Top, ListBox1->Items->Strings[Index]);
}


記得要先把 ListBox1 的 Style 屬性改成 lbOwnerDrawVariable
或是 lbOwnerDrawFixed

arrow
arrow

    yao67 發表在 痞客邦 留言(0) 人氣()