在OnDrawCell事件中写下面 with stringgrid1 of Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小 Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色 Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景 Canvas.FillRect(ARect); DrawText(Canvas.Handle,PChar(Cells[ACol,ARow]),Length(Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中 end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if ACol = 1 then begin StringGrid1.Canvas.Font.Color := clRed; StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'A'); StringGrid1.Canvas.Font.Color := clBlue; StringGrid1.Canvas.TextOut(Rect.Left+10,Rect.Top,'B'); StringGrid1.Canvas.Font.Color := clGreen; StringGrid1.Canvas.TextOut(Rect.Left+20,Rect.Top,'C'); end; end;
http://topic.csdn.net/t/20040324/20/2882325.html
...
with stringgrid1 of
Canvas.Font.Size:= CellFontBrush[ACol].Size; //字体大小
Canvas.Font.Color:= CellFontBrush[ACol].Color; //字体颜色
Canvas.Brush.color:=CellColorBrush[ACol];//颜色背景
Canvas.FillRect(ARect);
DrawText(Canvas.Handle,PChar(Cells[ACol,ARow]),Length(Cells[ACol,ARow]),ARect,1 or DT_SINGLELINE or 4); //文字居中
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ACol = 1 then
begin
StringGrid1.Canvas.Font.Color := clRed;
StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'A');
StringGrid1.Canvas.Font.Color := clBlue;
StringGrid1.Canvas.TextOut(Rect.Left+10,Rect.Top,'B');
StringGrid1.Canvas.Font.Color := clGreen;
StringGrid1.Canvas.TextOut(Rect.Left+20,Rect.Top,'C');
end;
end;