gpt4 book ai didi

德尔福5 : How to suspend anchor layouts?

转载 作者:行者123 更新时间:2023-12-03 15:20:46 27 4
gpt4 key购买 nike

有没有办法暂时暂停表单上所有锚定控件的移动或调整大小?即:

procedure ScaleFormBy(AForm: TForm; n, d: Integer);
begin
AForm.SuspendAnchors();
try
AForm.ScaleBy(n, d);
finally
AForm.ResumeAnchors();
end;
end;

我需要这样做,因为我正在打电话

AForm.ScaleBy(m, d);

它不能正确处理锚定控件。 (它将左+右或上+下锚定控件推离表单边缘。

注意:我想禁用 anchor ,而不是对齐。

最佳答案

SuspendAnchors 听起来像是一个基本方法,但我不认为它是基本 Delphi 语言的一部分:)下面是一些可以实现这一目的的代码:

<小时/>
var aAnchorStorage: Array of TAnchors;
procedure AnchorsDisable(AForm: TForm);
var
iCounter: integer;
begin
SetLength(aAnchorStorage, AForm.ControlCount);
for iCounter := 0 to AForm.ControlCount - 1 do begin
aAnchorStorage[iCounter] := AForm.Controls[iCounter].Anchors;
AForm.Controls[iCounter].Anchors := [];
end;
end;

procedure AnchorsEnable(AForm: TForm);
var
iCounter: integer;
begin
SetLength(aAnchorStorage, AForm.ControlCount);
for iCounter := 0 to AForm.ControlCount - 1 do
AForm.Controls[iCounter].Anchors := aAnchorStorage[iCounter];
end;

procedure TForm1.btnAnchorsDisableClick(Sender: TObject);
begin
AnchorsDisable(Self);
end;

procedure TForm1.btnAnchorsEnableClick(Sender: TObject);
begin
AnchorsEnable(Self);
end;
<小时/>

享受

关于德尔福5 : How to suspend anchor layouts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/587957/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com