抛砖引玉procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var Value : string; begin with TStringGrid(Sender) do begin Value := Cells[ACol,ARow]; if UpperCase(Cells[4,ARow])='TRUE' then Canvas.Brush.Color := clYellow else if UpperCase(Cells[4,ARow])='FALSE' then Canvas.Brush.Color := clGray else Canvas.Brush.Color := clWhite; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left,Rect.Top,Value); end; end;procedure TForm1.Button1Click(Sender: TObject); begin StringGrid1.Cells[4,1] := 'True'; StringGrid1.Cells[4,3] := 'False'; StringGrid1.Refresh; end;
Rect: TRect; State: TGridDrawState);
var Value : string;
begin
with TStringGrid(Sender) do
begin
Value := Cells[ACol,ARow];
if UpperCase(Cells[4,ARow])='TRUE' then
Canvas.Brush.Color := clYellow
else if UpperCase(Cells[4,ARow])='FALSE' then
Canvas.Brush.Color := clGray
else Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left,Rect.Top,Value);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
StringGrid1.Cells[4,1] := 'True';
StringGrid1.Cells[4,3] := 'False';
StringGrid1.Refresh;
end;