使用该ColWidths属性,如下所示:
with StringGrid1 do
ColWidths[1] := ClientWidth - ColWidths[0] - 2 * GridLineWidth;
Run Code Online (Sandbox Code Playgroud)
对于更强大和灵活的解决方案,请考虑所有固定列并参数化列索引:
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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13307 次 |
| 最近记录: |