Delphi元素如何实现中心对齐?

2026-04-10 20:082阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计250个文字,预计阅读时间需要1分钟。

Delphi元素如何实现中心对齐?

对齐属性非常有效,但需注意对齐元素。由于元素尺寸小于容器,所有元素都将对齐到底部。类似地,这样的布局:+ 或 至少水平平衡。

Delphi元素如何实现中心对齐?

似乎对齐属性非常有效,但是可以对齐元素,因此如果所有元素都小于容器大小,那么面板上的所有元素都将对齐到彼此底部的所有元素?像顶部中心的东西.

像这样的东西:

或至少水平,垂直,他们可以100%.

将元素放入自己的容器中,例如TPanel或TFrame,它是主容器的子容器.将子容器的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;

本文共计250个文字,预计阅读时间需要1分钟。

Delphi元素如何实现中心对齐?

对齐属性非常有效,但需注意对齐元素。由于元素尺寸小于容器,所有元素都将对齐到底部。类似地,这样的布局:+ 或 至少水平平衡。

Delphi元素如何实现中心对齐?

似乎对齐属性非常有效,但是可以对齐元素,因此如果所有元素都小于容器大小,那么面板上的所有元素都将对齐到彼此底部的所有元素?像顶部中心的东西.

像这样的东西:

或至少水平,垂直,他们可以100%.

将元素放入自己的容器中,例如TPanel或TFrame,它是主容器的子容器.将子容器的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;