加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi 5:如何暂停锚布局?

发布时间:2020-12-15 09:37:21 所属栏目:大数据 来源:网络整理
导读:有没有办法暂停表单上的所有锚定控件暂时移动或调整大小?即: procedure ScaleFormBy(AForm: TForm; n,d: Integer);begin AForm.SuspendAnchors(); try AForm.ScaleBy(n,d); finally AForm.ResumeAnchors(); end;end; 我需要这样做,因为我正在打电话 AForm.
有没有办法暂停表单上的所有锚定控件暂时移动或调整大小?即:

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

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

AForm.ScaleBy(m,d);

哪个不能正确处理锚定控件. (它将左侧或顶部底部锚定的控件推离表单的边缘.

注意:我想禁用Anchors,而不是Alignment.

解决方法

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;

请享用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读