在OnDrawwCell中, procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1.Canvas do begin // 根据各种条件设置颜色 if (ACol = 1) and (ARow = 2) then Font.Color := clBlue else if (ACol = 2) and (ARow = 1) then Font.Color := clRed; TextOut(Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]); end; end;
調試過了,沒問題: procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if gdFixed in state then Exit; If StringGrid1.Cells[ACol,ARow]='A' then stringgrid1.Canvas.Font.Color:=clBlue else stringgrid1.Canvas.Font.Color:=clRed; stringgrid1.Canvas.Font.Height:=16; stringgrid1.Canvas.Font.Style:=[fsBold]; stringgrid1.canvas.textout(rect.left+3,rect.top+6,StringGrid1.Cells[ACol,ARow]); end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1.Canvas do begin
// 根据各种条件设置颜色
if (ACol = 1) and (ARow = 2) then
Font.Color := clBlue
else
if (ACol = 2) and (ARow = 1) then
Font.Color := clRed;
TextOut(Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]);
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdFixed in state then Exit;
If StringGrid1.Cells[ACol,ARow]='A' then
stringgrid1.Canvas.Font.Color:=clBlue
else
stringgrid1.Canvas.Font.Color:=clRed;
stringgrid1.Canvas.Font.Height:=16;
stringgrid1.Canvas.Font.Style:=[fsBold];
stringgrid1.canvas.textout(rect.left+3,rect.top+6,StringGrid1.Cells[ACol,ARow]);
end;