因为工作上的需要得实现这个功能,查找了下相关的资料在这里和大家分享下。
首先来说下列表控件的字体改变实现方式:
选中列表控件并重载OnCustomDrawItem函数,这是列表重绘的响应函数。
(1)特定行显示字体颜色
void __fastcall TForm1::lvCustomDrawItem( TCustomListView *Sender, TListItem *Item, TCustomDrawState State, TCustomDrawStage Stage, bool &DefaultDraw)
{
if(Item->Index==0) //0 行 (特定行)
{
Sender->Canvas->Brush->Color = clWhite ;
Sender->Canvas->Font->Color = clBlue; //字体为 clBlue 颜色
}
else
Sender->Canvas->Brush->Color = clWhite;
}
(2)特定列显示字体颜色
void __fastcall TForm1::lvCustomDrawItem( TCustomListView *Sender, TListItem *Item, TCustomDrawState State, TCustomDrawStage Stage, bool &DefaultDraw)
{
if(SubItem==3) //2列 (特定列)
{
Sender->Canvas->Brush->Color = clWhite ;
Sender->Canvas->Font->Color = clBlue; //字体为 clBlue 颜色
}
else
{
Sender->Canvas->Brush->Color = clWhite;
Sender->Canvas->Font->Color = clBlack; //字体为 clBlack 颜色
}
}
(3)特定行和列的交汇
void __fastcall TForm1::lvCustomDrawItem( TCustomListView *Sender, TListItem *Item, TCustomDrawState State, TCustomDrawStage Stage, bool &DefaultDraw)
{
if(Item->Index==3) //3行 (特定行)
if(SubItem==3) //2列 (特定列)
{
Sender->Canvas->Brush->Color = clWhite ;
Sender->Canvas->Font->Color = clBlue; //字体为 clBlue 颜色
}
}
之后再来说说treeview的实现了。
同样是重载:OnCustomDrawItem函数,
void __fastcall TForm1::tvCustomDrawItem(TCustomTreeView *Sender, TTreeNode *Node, TCustomDrawState State,bool &DefaultDraw)
{
if (Node->Text == "1111") //符合条件的节点
{
Sender->Canvas->Font->Color=clBlue;
}
}