Is there a way to suspend all anchored controls on a form from moving or resizing themselves temporarily? i.e.:
procedure ScaleFormBy(AForm: TForm; n, d: Integer);
begin
AForm.SuspendAnchors();
try
AForm.ScaleBy(n, d);
finally
AForm.ResumeAnchors();
end;
end;
I need to do this because I'm calling
AForm.ScaleBy(m, d);
Which does not handle anchored controls properly. (it pushes left+right or top+bottom anchored controls off the edge of the form.
Note: I want to disable Anchors, not Alignment.
SuspendAnchors sound like a base method but I don't think it's part of the base Delphi language :) Here is some code that does the trick:
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;
Enjoy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With