把StringGrid的DefaultDrawing设为False,然后在OnDrawCell里模拟所有正常的描绘动作:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
StringGrid1.Canvas.Font.Assign(StringGrid1.Font);//这一句可以放到Form的OnCreate里
with StringGrid1.Canvas do begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then Brush.Color := StringGrid1.FixedColor;
FillRect(Rect);
with StringGrid1 do
TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
end;
end;