如何使StringGrid的列适合网格的宽度? [英] How do I make a StringGrid's columns fit the grid's width?

查看:186
本文介绍了如何使StringGrid的列适合网格的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个没有任何运气的解决方案。有谁知道一个简单的方法来做到这一点?我想拉伸例如我的网格的第二柱适合网格的宽度!

解决方案

使用 ColWidths 属性,如下所示:

  with StringGrid1 do 
ColWidths [1] := ClientWidth - ColWidths [0] - 2 * GridLineWidth;

对于更强大和更灵活的解决方案,请考虑所有固定列并对列索引进行参数化:

  procedure SetColumnFullWidth(Grid:TStringGrid; ACol:Integer); 
var
I:Integer;
FixedWidth:Integer;如果ACol> = FixedCols,则
以Grid
开始
然后
begin
FixedWidth:= 0;
for I:= 0 to FixedCols - 1 do
Inc(FixedWidth,ColWidths [I] + GridLineWidth);
ColWidths [ACol]:= ClientWidth - FixedWidth - GridLineWidth;
end;
end;

程序TForm1.Button1Click(发件人:TObject);
begin
SetColumnFullWidth(StringGrid1,4);
end;


I've been looking for a long time for a solution without any luck. Does anyone know a simple way to do that? I would like to stretch for example the second colum of my grid to fit the grid's width!

解决方案

Use the ColWidths property, like so:

with StringGrid1 do
  ColWidths[1] := ClientWidth - ColWidths[0] - 2 * GridLineWidth;

And for a more robust and flexible solution, take all fixed columns into account and parameterize the column index:

procedure SetColumnFullWidth(Grid: TStringGrid; ACol: Integer);
var
  I: Integer;
  FixedWidth: Integer;
begin
  with Grid do
    if ACol >= FixedCols then
    begin
      FixedWidth := 0;
      for I := 0 to FixedCols - 1 do
        Inc(FixedWidth, ColWidths[I] + GridLineWidth);
      ColWidths[ACol] := ClientWidth - FixedWidth - GridLineWidth;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetColumnFullWidth(StringGrid1, 4);
end;

这篇关于如何使StringGrid的列适合网格的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆