procedure TTestPage_frm.grdRackDrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
RowColor : TBrush;
//b : TRectF;
begin
RowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
if Value.ToString = sOffline then
RowColor.Color := TAlphaColors.Red
else if grdRack.Selected = Row then
RowColor.Color := TAlphaColors.Cornflowerblue
else
RowColor.Color := TAlphaColors.White;
Canvas.FillRect(Bounds, 1, 1, [], 1, RowColor);
{ perform default drawing }
TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
Value, State);
RowColor.Free;
inherited;
end;
有表格的:
var aRowColor: TBrush; aNewRectF: TRectF; begin aRowColor := TBrush.Create(TBrushKind.Solid, TAlphaColors.Alpha); if (StringGrid1.Cells[7, Row] = '1') then aRowColor.Color := TAlphaColors.Green else aRowColor.Color := TAlphaColors.Red; aNewRectF := Bounds; aNewRectF.Inflate(3, 3); Canvas.FillRect(aNewRectF, 0, 0, [], 1, aRowColor); Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State); aRowColor.free;