gpt4 book ai didi

Delphi 元素对齐方式 - 居中

转载 作者:行者123 更新时间:2023-12-03 15:18:22 32 4
gpt4 key购买 nike

似乎有一个 align 属性工作得非常好,但是可以对齐元素,因此面板上的所有元素都将对齐,以在彼此底部居中,如果它们都小于容器尺寸?类似顶部中心中心的东西。

类似这样的事情:

Something like this

或者至少水平方向和垂直方向可以有 100%。

最佳答案

将元素放入它们自己的容器中,例如 TPanelTFrame,它们是主容器的子容器。将子容器的 Align 属性设置为 alCustom 并使用父容器的 OnAlignPosition 事件使子容器保持自身居中:

// Panel1 is the Parent container for the child panel...
procedure TMyForm.Panel1AlignPosition(Sender: TWinControl; Control: TControl;
var NewLeft, NewTop, NewWidth, NewHeight: Integer; var AlignRect: TRect;
AlignInfo: TAlignInfo);
begin
if Control = ChildPanel then
begin
NewLeft := AlignRect.Left + ((AlignRect.Width - Control.Width) div 2);
NewTop := AlignRect.Top + ((AlignRect.Height - Control.Height) div 2);
end;
end;

关于Delphi 元素对齐方式 - 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23744047/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com