zoukankan      html  css  js  c++  java
  • Delphi xe8 FMX StringGrid根据内容自适应列宽。

    Delphi xe8 FMX StringGrid根据内容自适应列宽。


    网上的资料比较复杂,而且不是根据字体字号等设置列宽。故自己写了个function来用。


    function GetColMaxDataLength(ASGrid: TStringGrid): TObject;
    var
      MaxColLength,                  //列数据的最大长度
      CellLength: Single;            //单元格长度
      ACol,ARow: Integer;
    begin
      with ASGrid do
      begin
        for ACol := 0 to ColumnCount - 1 do
        begin
          MaxColLength:=Canvas.TextWidth(Columns[ACol].Header);//取列头宽度
          for ARow := 0 to RowCount - 1 do
          begin
            CellLength := Canvas.TextWidth(Cells[ACol,ARow]);//取单元格宽度
            if CellLength > MaxColLength then
              MaxColLength := CellLength;
          end;
          Columns[ACol].Width := MaxColLength + 20;  //加上一个值调整列宽
        end;
      end;
    end;


    应用很简单,一句搞定:
    GetColMaxDataLength(StringGrid1);
    ---------------------
    作者:ooooh
    来源:CSDN
    原文:https://blog.csdn.net/ooooh/article/details/50551212
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    yum error
    Linux如何查询内存真实利用率
    管理工作
    top 详解
    炒股
    vsftp+apache中文乱码问题
    生活像杯咖啡
    vmware workstation 9 nat setting
    cp文件
    WPF 数据分页控件改进
  • 原文地址:https://www.cnblogs.com/kinglandsoft/p/10636548.html
Copyright © 2011-2022 走看看