2。也在OnDrawCell里控制
Canvas.Font.color := ...
Canvas.Font.Style := ...
背景用
Canvas.brush.color:=...
Canvas.brush.Style := ...
Canvas.FillRect(Rect);
居中可以用DrawText控制,参数dt_center
【转载】
将StringGrid的DefaultDrawing设为False,再在OnDrawCell事件中加上下列东东,假设你的
StringGrid名称为StrGrid.建议你以后提问前搜一下,这儿有许多相同的问题.
procedure TFrmEdtData.StrGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var Area:TRect;
begin
StrGrid.Canvas.Font.Assign(StrGrid.Font);
with StrGrid,StrGrid.Canvas do
begin
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2);
if (ACol<2) or (ARow=0) then
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER)//居中
else
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_RIGHT);//右对齐
end;
end;