procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
s: String;
R: TRect;
begin
with StringGrid1 do
begin
if ARow=0 then Canvas.Font.Color := clWhite;
if ACol=0 then Canvas.Font.Color := clWhite;
if Cells[ACol,ARow] = '变色' then //找到内容为'变色'的单元格然后进行设置
begin
Canvas.Font.Color := clMaroon; //字体颜色
Canvas.Brush.color:=clMoneyGreen; //背景颜色
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
end;
Canvas.FillRect(Rect);
S := Cells[ACol,ARow];
R := Rect;
DrawText(Canvas.Handle,PChar(s),Length(s),r,DT_CENTER or DT_SINGLELINE or DT_VCENTER); //文字居中
end;
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2011/12/29/2305731.html