procedure TForm1.FormShow(Sender: TObject); begin StringGrid1.Cells[0,0]:='我'; StringGrid1.Cells[1,0]:='爱'; StringGrid1.Cells[2,0]:='中'; StringGrid1.Cells[3,0]:='国'; end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var sText: String; begin sText:=StringGrid1.Cells[ACol,ARow]; StringGrid1.Canvas.Font.Name:='宋体'; StringGrid1.Canvas.Font.Size:=11; if ACol=0 then StringGrid1.Canvas.Font.Color:=clRed; if ACol=1 then StringGrid1.Canvas.Font.Color:=clBlue; if ACol=2 then StringGrid1.Canvas.Font.Color:=clYellow; StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,sText);end; 自己用代码控制需要改变颜色的地方
begin
StringGrid1.Cells[0,0]:='我';
StringGrid1.Cells[1,0]:='爱';
StringGrid1.Cells[2,0]:='中';
StringGrid1.Cells[3,0]:='国';
end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
sText: String;
begin
sText:=StringGrid1.Cells[ACol,ARow];
StringGrid1.Canvas.Font.Name:='宋体';
StringGrid1.Canvas.Font.Size:=11;
if ACol=0 then
StringGrid1.Canvas.Font.Color:=clRed;
if ACol=1 then
StringGrid1.Canvas.Font.Color:=clBlue;
if ACol=2 then
StringGrid1.Canvas.Font.Color:=clYellow;
StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,sText);end;
自己用代码控制需要改变颜色的地方