Delphi元素如何实现中心对齐?
- 内容介绍
- 文章标签
- 相关推荐
本文共计250个文字,预计阅读时间需要1分钟。
对齐属性非常有效,但需注意对齐元素。由于元素尺寸小于容器,所有元素都将对齐到底部。类似地,这样的布局:+ 或 至少水平平衡。
像这样的东西:
或至少水平,垂直,他们可以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分钟。
对齐属性非常有效,但需注意对齐元素。由于元素尺寸小于容器,所有元素都将对齐到底部。类似地,这样的布局:+ 或 至少水平平衡。
像这样的东西:
或至少水平,垂直,他们可以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;

