Delphi:如何使用align = alTop以编程方式调整组件的视觉顺序

发布于 2024-07-30 06:21:20 字数 127 浏览 11 评论 0原文

我有一个包含多个面板的表单,每个面板都有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

梨涡少年 2024-08-06 06:21:20

尝试使用一列和 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).

怎樣才叫好 2024-08-06 06:21:20

如果更改面板的顶部,面板的视觉顺序会发生变化。

试试这个(所有面板altop对齐并且具有相同的高度):

PANEL0
面板1
面板2
面板3
PANEL4

所有面板OnClick事件中执行以下操作:

 TPanel(Sender).Top := TPanel(Sender).Top - TPanel(Sender).Height - 2;

如果单击某个面板,它会向上移动一个位置。

就是这个想法。 更改前 X 个像素。
同时,如果执行以下操作:

   TPanel(Sender).Top := TPanel(Sender).Top - (TPanel(Sender).Height * 2)- 2; 

面板上升 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:

 TPanel(Sender).Top := TPanel(Sender).Top - TPanel(Sender).Height - 2;

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:

   TPanel(Sender).Top := TPanel(Sender).Top - (TPanel(Sender).Height * 2)- 2; 

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

沩ん囻菔务 2024-08-06 06:21:20

我使用了以下代码:

procedure Show_Hide (Flag_Show : boolean);
begin
  if Flag_Show then
  begin
    with Panel_1 do begin Align := alTop; Visible := true; end;
    with Panel_2 do begin Align := alTop; Visible := true; end;
    with Panel_3 do begin Align := alTop; Visible := true; end;
    with Panel_4 do begin Align := alTop; Visible := true; end;
  end else
  begin
    with Panel_1 do begin Visible := false; Align := alNone; end;
    with Panel_2 do begin Visible := false; Align := alNone; end;
    with Panel_3 do begin Visible := false; Align := alNone; end;
    with Panel_4 do begin Visible := false; Align := alNone; end;
  end;
end;

根据我的意愿
面板_1
面板_2
面板_3
面板_4

I've used the following code:

procedure Show_Hide (Flag_Show : boolean);
begin
  if Flag_Show then
  begin
    with Panel_1 do begin Align := alTop; Visible := true; end;
    with Panel_2 do begin Align := alTop; Visible := true; end;
    with Panel_3 do begin Align := alTop; Visible := true; end;
    with Panel_4 do begin Align := alTop; Visible := true; end;
  end else
  begin
    with Panel_1 do begin Visible := false; Align := alNone; end;
    with Panel_2 do begin Visible := false; Align := alNone; end;
    with Panel_3 do begin Visible := false; Align := alNone; end;
    with Panel_4 do begin Visible := false; Align := alNone; end;
  end;
end;

according my wish
Panel_1
Panel_2
Panel_3
Panel_4

茶色山野 2024-08-06 06:21:20

我知道这是一篇旧文章,但基本上对我有帮助 - 将顶部属性设置为零的想法。
我无法使用以编程方式设置位置的想法,因为这取决于应用程序用户 - 它可以选择在应用程序上显示一些图表,然后,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.

皓月长歌 2024-08-06 06:21:20

通过将顶部对齐面板的 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.

_畞蕅 2024-08-06 06:21:20

移动它们的方式与设计时使用鼠标移动它们的方式相同:将当前面板的 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 the Top 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 with DeferWindowPos, and then make them all move at once with EndDeferWindowPos.

廻憶裏菂餘溫 2024-08-06 06:21:20

我建议构建一个框架,您可以在其中动态地从其父控件中删除表单或向其父控件添加表单。 一般来说,创建/添加的顺序是视觉顺序,但从您的问题来看,我了解您希望在应用程序生命周期内更改顺序,因此仅更改原始创建顺序是不够的。

要更改顺序,请尝试:

  1. 隐藏面板
  2. 从其父控件中删除面板 将
  3. 面板按照您希望的新顺序添加到其父控件
  4. 显示面板

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:

  1. Hide the panels
  2. Remove the panels from their parent control
  3. Add the panels to their parent control in the new order you wish
  4. Show the panels
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文