What is your preferred way of keeping controls centered on its parent when the parent change width or height?
+4
A:
Set control's Anchors property to [akLeft, akTop, akRight, akBottom].
gabr
2008-11-24 09:49:24
This is indeed the way to do it.
Gamecat
2008-11-24 09:50:29
This assumes the childcontrol is allowd to resize.
Vegar
2008-11-24 10:10:12
Yes. The other answer describes the non-resizing approach.
gabr
2008-11-24 10:27:56
+5
A:
If by 'centered' you mean "it was already in the middle and you want to keep it there without resizing it", then remove all anchors. If it should be resized, gabr's solution is the one to with :)
Vincent Van Den Berghe
2008-11-24 10:11:26
A:
If you mean a sort of "updating, please wait..." type thing, I manually move it in the Form's OnResize event. This allows me to keep a panel out of the way during design, and hidden normally, but I can make it visible when needed.
procedure TMyForm.FormResize(Sender: TObject);
var
nNewTop : Integer;
begin
inherited;
pnlRegenerating.Left := (ClientWidth - pnlRegenerating.Width) div 2;
nNewTop := (ClientHeight div 5) {* 4};
if (nNewTop + pnlRegenerating.Height) > ClientHeight then
nNewTop := ClientHeight - pnlRegenerating.Height - 4;
pnlRegenerating.Top := nNewTop;
end;
mj2008
2008-11-24 10:49:52