打印本文 打印本文 关闭窗口 关闭窗口
动态更新DBGrid的颜色
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1066  更新时间:2009/4/23 18:44:18  文章录入:mintao  责任编辑:mintao
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;

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

打印本文 打印本文 关闭窗口 关闭窗口