使TStringGrid自适应宽度
2006-02-04 13:56:07 来源:WEB开发网核心提示:PRocedure AutoFitable(AGrids: TStringGrid);//传入TStringGrid对像即可, 2004/10/28,CoolSlobvar I, J: Integer; MaxLenRow: Integer; CurRowLen: Integer;begin inherited
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;
//传入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;
Tags:TStringGrid 适应 宽度
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接