在OnDrawCell,以下为右对齐代码
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
l_Left, l_Top: Integer;
begin
l_Left := (StringGrid1.Colwidths[ACol] - StringGrid1.Canvas.Textwidth(StringGrid1.Cells[ACol, ARow]) - 2); //右对齐
l_Top := (StringGrid1.Rowheights[ARow] - StringGrid1.Canvas.Textheight(StringGrid1.Cells[ACol, ARow])) div 2;
StringGrid1.Canvas.Textrect(Rect, Rect.Left + l_Left, Rect.Top + l_Top, StringGrid1.Cells[ACol, ARow]);
end;