用的是StringGrid
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
NewColor:TColor;
begin
Randomize();
NewColor:=RGB(Random(255),Random(255),Random(255));
self.StringGrid1.Canvas.Brush.Color:=NewColor;
self.StringGrid1.Canvas.FillRect(Rect);
self.StringGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,self.StringGrid1.Cells[ACol,ARow]);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j:Integer;
begin
for i:=0 to self.StringGrid1.ColCount-1 do
begin
for j:=0 to self.StringGrid1.RowCount-1 do
begin
self.StringGrid1.Cells[i,j]:= IntToStr(i*j);
end;
end;
end;