BCB中listview和treeview控件实现制定列和标题字体颜色改变的实现

   因为工作上的需要得实现这个功能,查找了下相关的资料在这里和大家分享下。

   首先来说下列表控件的字体改变实现方式:

   选中列表控件并重载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;

     }

}

猜你喜欢

转载自blog.csdn.net/zh516846937/article/details/7087001