使TStringGrid自适应宽度

2016-02-19 16:24 3 1 收藏

下面请跟着图老师小编一起来了解下使TStringGrid自适应宽度,精心挑选的内容希望大家喜欢,不要忘记点个赞哦!

【 tulaoshi.com - 编程语言 】

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;

来源:https://www.tulaoshi.com/n/20160219/1612002.html

延伸阅读
我们知道,屏幕分辨率的设置影响着表单布局,假设你的机器上屏幕分辨率是800*600,而最终 要分发应用的机器分辨率为640*480,或1024*768,这样你原先设计的表单在新机器上势必会 走样。这时你一定希望表单能自己适应不同的分辨率,下面就有两种方法可供你参考。 一、根据新的分辨率自动重画表单及控件 先在表单单元的Interface部...
标签: Web开发
div下图片自适应解决方法 以前的解决方法主要是利用js来实现,但用过的人都知道该办法有点繁琐。还有一种是在外部容器定义over-flow:hidden。但这种办法只会切割图片而不会自动适用。  关键在于:max-width:780px;以及下面那行。 固定像素适应: dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc ...
标签: Web开发
main.htm: html       head          meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312' /          meta  name='author'  c...
标签: Web开发
前言 有时候我们不得不面对圆角,也很傻很天真的认为利用 CSS3 的新特性对浏览器分级支持是最好解决方案,但现实≠理想 需求3px 圆角 宽度自适应(随着文字字数扩展宽度并自动换行) 换肤 不使用图片(对可维护性/性能均有影响) 困惑 经典的解决方案看起来像这样: !DOCTYPE htmlhtmlheadmeta content="text/html; charset=utf-8&qu...
标签: Web开发
htmlhead meta http-equiv="Content-Type" content="text/html; charset=gb2312" meta name="GENERATOR" content="Microsoft FrontPage 4.0" meta name="ProgId" content="FrontPage.Editor.Document" titleNew Page 1/title /head body IFRAME id="test" name="...

经验教程

608

收藏

91
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部