动态更新DBGrid的颜色

类别:Delphi 点击:0 评论:0 推荐:
DBGrid控件是一个有许多用户接口的显示数据库的控件,以下的程序
告诉您如何根据显示的内容改变字体的显示颜色。例如,如果一个城
市的人口大于200万,我们就让它显示为蓝色。使用的控件事件为
DBGrid.OnDrawColumeCell.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const
Rect:TRect;DataCol: Integer; Column: TColumn; State:
TGridDrawState);

begin

if Table1.FieldByName('Population').AsInteger > 20000000 then

DBGrid1.Canvas.Font.Color := clBlue;

DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

上面的例子是简单的,但是你可以根据自己的需要扩充,例如字体也
变化等,甚至你可以调用画圆的函数在数字上画上一个红色的圆圈。

本文地址:http://com.8s8s.com/it/it6090.htm