delphi DBGrid简单自绘(字体颜色、背景等)
从网上找的代码 应该是C#写的,其实delphi 的操作类似:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void
__fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender,
const
TRect &Rect,
int
DataCol, TColumn *Column,
TGridDrawState State)
{
AnsiString name= Column->Field->DataSet->FieldByName(
"NAME"
)->AsString;
if
(name==
"功能科室"
&&DataCol==1)
//只绘制name为功能科室行和第二列的交集
DBGrid1->Canvas->Font->Color=clRed;
if
(name==
"心电图室"
)
DBGrid1->Canvas->Font->Color=clGreen;
if
(name==
"胃镜室"
)
DBGrid1->Canvas->Brush->Color=clGreen;
DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);
//是什么意思??
}
|