procedure AutoFitable(AGrids: TStringGrid); //傳入TStringGrid對像即可, 2004/10/28,CoolSlob var I, J: Integer; MaxLenRow: Integer; CurRowLen: Integer; begin inherited; for J := 0 to AGrids.ColCount - 1 do begin MaxLenRow := 0; for I := 1 to AGrids.RowCount - 1 do begin CurRowLen := AGrids.Canvas.TextWidth(Trim(AGrids.Cells[J, I])); //自適應寬度時,當值的最大寬度小於標題寬時,以標題寬為准。 if AGrids.Canvas.TextWidth(Trim(AGrids.Cells[J, 0])) > CurRowLen then CurRowLen := AGrids.Canvas.TextWidth(Trim(AGrids.Cells[J, 0])); if CurRowLen > MaxLenRow then begin MaxLenRow := CurRowLen + 5; AGrids.ColWidths[J] := MaxLenRow; end; end; end; end;