德尔福5 : How to suspend anchor layouts?

标签 delphi layout user-interface fonts

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

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/

相关文章:

java - 这个 XML 有什么问题吗?滑动抽屉/布局

java - 如何为 GridBagLayout 设置约束

java - 让两个JList同时滚动

java - 如何链接到包但仅根据运行时包的存在/可用性选择性地执行操作?

php - MD5 文件哈希 - 将 Delphi 输出与 PHP md5_file 函数匹配

delphi - 以分钟/秒为单位获取wav音频的长度

delphi - 寻找免费的、可定制的数据库网格

delphi - Delphi XE4 中使用 SVN 进行单文件版本控制

css - 通过 Flex Box 进行简单布局

c++ - DLL 中的 Qt GUI 环境(VST 插件)