从以前的DFW记录中摘抄:供参考
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Code: Integer;
Bmp: TBitmap;
begin
// erase existing output
DBGrid1.Canvas.FillRect (Rect);
if Column.Field = Table1Graphic then
begin
// draw the image
Bmp := TBitmap.Create;
try
Bmp.Assign (Table1Graphic);
DBGrid1.Canvas.StretchDraw (Rect, Bmp);
finally
Bmp.Free;
end;
end
else
begin
// choose the font color
if (Column.Field = Table1Lengthcm) and
(Table1Lengthcm.AsInteger > 100) then
DBGrid1.Canvas.Font.Color := clRed
else if gdSelected in State then
DBGrid1.Canvas.Font.Color := clHighlightText
else
DBGrid1.Canvas.Font.Color := Column.Font.Color;
// draw the standard text
DBGrid1.Canvas.TextRect (
Rect, Rect.Left, Rect.Top,
Column.Field.AsString);
end;
// optionally draw the focus rectangle
if gdFocused in State then
DBGrid1.Canvas.DrawFocusRect (Rect);
end;
delphi4从入门道精通上的例子