锚:= [akCenter]? [英] Anchors := [akCenter]?
问题描述
我如何中心其父项内的控制?而如何保持它为中心当父调整大小?
How can I center a control within its parent? And how to keep it centered when the parent resizes?
我知道我可以写一个 Parent.OnResize
事件处理程序手动移动控制,但不是所有的容器组件有一个 onResize受到
事件,我想自动执行此操作。
I know I could write a Parent.OnResize
event handler to move the control manually, but not all container components have an OnResize
event, and I would like to do this automatically.
有一个 akCenter
主播?
推荐答案
锚 akCenter
不存在。但是,你可以模仿 akRelative
通过设置锚点属性空导致当父调整大小控制的相对运动。结合,与中心的位置将导致中心,都锚。
The anchor akCenter
does not exist. But you can mimic akRelative
by setting the anchors property empty which results in relative movement of the control when the parent resizes. Combining that with centered placement will result in a centered-alike "anchor".
要水平居中在设计时:
- 在IDE中,选择控制的上下文菜单(右键单击),
- 的位置>对齐>水平>中心窗口的
- 设置
Anchors.akLeft:=假
,Anchors.akRight:=假
在Object Inspector, - 等瞧:
akHorzCenter
- In the IDE, choose the context menu of the control (right click),
- Position > Align > Horizontal > Center in Window,
- Set
Anchors.akLeft := False
,Anchors.akRight := False
in the object inspector, - Et voilà :
akHorzCenter
.
这同样适用于垂直,在这种情况下,您设置 akTop
和 akBottom
假的。要居中在两个方向:锚:= []
The same goes for vertical, in which case you set akTop
and akBottom
false. To center in both directions: Anchors := []
.
免责声明:我还没有发现这个文档锚的使用,我不知道这是否是预期的功能,但它的工作原理很不错的D7以及在XE2
Disclaimer: I have not found documentation of this anchors usage and I do not know whether this is the intended functioning, but it works very nice in D7 as well as in XE2.
这篇关于锚:= [akCenter]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!