关闭stringgrid的defaultdrawing功能
StringGrid1.Cells[cCol,cRow] := '测试1'+#13#10+'测试2';
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Area:TRect;
begin
StringGrid1.Canvas.Font.Assign
(StringGrid1.Font);
with StringGrid1,StringGrid1.Canvas do
begin
//变色功能
Canvas.Font.Color := clred; //字体颜色为红的
Canvas.Brush.color := clMoneyGreen; //背景为 美元绿色
Canvas.FillRect(Rect);
FillRect(Rect);
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2);
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER)//居中
end;
end;