打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使TStringGrid自适应宽度
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;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Delphi 的绘图功能[15]
DBGRIDEH自动(标题)列宽
Excel 请教一个关于CODE128条形码宽度的问题
删除A列重复行
在不同版本Excel中插入图片
VB打印功能全代码
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服