有没有办法暂时暂停表单上所有锚定控件的移动或调整大小?即:
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/