Delphi:如何使用align = alTop以编程方式调整组件的视觉顺序
我有一个包含多个面板的表单,每个面板都有 Align=alTop
,因此它们可以很好地从表单顶部向下堆叠。
但是,我想动态更改这些面板的外观顺序 - 即上下移动它们。 这样做的最佳方法是什么?
I've got a form with a number of panels, each of which has Align=alTop
, so they stack down nicely from the top of the form.
However, I want to dynamically change the appearance order of these panels - i.e, move them up and down. What's the best way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试使用一列和 n 行的顶部对齐
TGridPanel
怎么样 --- 重新排序顶部对齐面板确实有点痛苦。(注意:
TGridPanel
在 Delphi 2007 及更高版本中可用,如果我没记错的话)。How about trying a top-aligned
TGridPanel
with one column and n rows instead --- re-ordering top-aligned panels is a bit of a pain, really.(Note:
TGridPanel
is available in Delphi 2007 and up, if I remember correctly).如果更改面板的顶部,面板的视觉顺序会发生变化。
试试这个(所有面板altop对齐并且具有相同的高度):
PANEL0
面板1
面板2
面板3
PANEL4
在所有面板的OnClick事件中执行以下操作:
如果单击某个面板,它会向上移动一个位置。
就是这个想法。 更改前 X 个像素。
同时,如果执行以下操作:
面板上升 2 个位置。
添加:如果您使用拖放,此事件将返回位置(X 和 Y); 通过原始位置和结束位置,您可以计算用于分配给面板的线顶。
请原谅我糟糕的英语。
问候
If you change the top of the panel the order of visually panel change.
Try this (all the panels aligned altop and with the same Height):
PANEL0
PANEL1
PANEL2
PANEL3
PANEL4
At OnClick event of all panels do this:
If you click on a panel it moves up one position.
That's the idea. Change the Top X pixels.
At the same, if you do this:
The panel up 2 positions.
ADDED: If you use Drag&Drop, this events return the position (X and Y); With the original position and end position you can calculate the wew top for asign to the panel.
Excuse form my poor english.
regards
我使用了以下代码:
根据我的意愿
面板_1
面板_2
面板_3
面板_4
I've used the following code:
according my wish
Panel_1
Panel_2
Panel_3
Panel_4
我知道这是一篇旧文章,但基本上对我有帮助 - 将顶部属性设置为零的想法。
我无法使用以编程方式设置位置的想法,因为这取决于应用程序用户 - 它可以选择在应用程序上显示一些图表,然后,teecharts 的所有面板(父级)都在顶部对齐。
我按照相反的顺序将它们的 top 属性设置为 0,然后根据用户输入设置可见的 true 或 false...
谢谢。
I know its an old post but basically helped me - the idea of setting the top property to zero.
I cant use the idea of programatically set the position cause this is up to the app user - it can chose to display some charts on the app and then, all the panels (parent) of the the teecharts are align altop.
I set their top property to 0 on the inverse order and then just set visible true or false according to user input...
Thanks.
通过将顶部对齐面板的 Top 属性设置为 0,您可以轻松地将顶部对齐面板移动到顶部。 按照相反的顺序执行此操作(首先是底部面板),您就完成了。
You can easily move a top-aligned panel to the top by setting its Top property to 0. Do this in reverse requested order (bottom panel first) and you are done.
移动它们的方式与设计时使用鼠标移动它们的方式相同:将当前面板的
Top
属性设置为比您想要移动的面板的Top
属性小 1位于当前面板下方。 VCL 将处理剩下的事情。如果您必须移动多个面板,请从
BeginDeferWindowPos
< 开始/a>. 使用DeferWindowPos
将所有面板调整到您想要的任何坐标,然后使用EndDeferWindowPos
让它们同时移动。Move them the same way you'd move them at design time with the mouse: Set the current panel's
Top
property to one less than theTop
property of the panel you want to be below the current panel. The VCL will take care of the rest.If you have to move several panels, start with
BeginDeferWindowPos
. Adjust all the panels to whatever coordinates you want withDeferWindowPos
, and then make them all move at once withEndDeferWindowPos
.我建议构建一个框架,您可以在其中动态地从其父控件中删除表单或向其父控件添加表单。 一般来说,创建/添加的顺序是视觉顺序,但从您的问题来看,我了解您希望在应用程序生命周期内更改顺序,因此仅更改原始创建顺序是不够的。
要更改顺序,请尝试:
I suggest building a framework where you dynamically remove/add the forms from/to their parent control. In general, the order of creation/addition is the visual order, but from your question I understand you want the order to change during the application lifetime, so just changing the original creation order won't be enough.
In order to change the order, try: