——此文章摘自《Delphi开发经验技巧宝典》定价¥特价¥ 购买>> 本例实现在表格中把年龄小于等于岁的年龄字段的矩形区域颜色改为红色把年龄大于岁的年龄字段的矩形区域颜色改为绿色如图所示 图 改变表格列的矩形区域颜色 通过表格的CanvasTextRect方法改变矩形区域的颜色主要代码如下 procedure TFrmOrderByDBGListDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var TemRect: TRect; RWidth: Integer; RHeigh: Integer; begin TemRectTop := RectTop + ; TemRectBottom := RectBottom ; RHeigh := TemRectBottom TemRectTop; RWidth := RectRight RectLeft; RWidth := (RWidth RHeigh) div ; TemRectLeft := RectLeft + RWidth; TemRectRight := TemRectLeft + RHeigh; if ColumnTitleCaption = 年龄 then begin DBGListCanvasTextRect(Rect ); if ColumnFieldAsInteger <= then DBGListCanvasBrushColor := clRed else DBGListCanvasBrushColor := clLime; DBGListCanvasFillRect(TemRect); end; end; |