Jump to content
Dave Craggs

Panels and alignment

Recommended Posts

If you have a panel with items inside all aligned left. How do you maintain the order when you change visibility? The items start in the correct order, but it you hide one and then later make it visible, it can end up in the wrong position. 

 

 

Share this post


Link to post

OK got it.

 

Hide all the controls and set align to alNone.

 

then go though in the order that you want setting them to visible and align to alLeft.

Share this post


Link to post

You can also rearrange visible controls by setting the .Left property to the previous control's Left + 1. That way, it will be placed immediately after it.

You might also want to wrap everything in Container.DiableAlign and .EnableAlign so you get the results you want to see.

Share this post


Link to post

maybe putting all "panel (with your alignment)" in a "PANEL" then, can help you not? if in FMX, use a TLayout

 

procedure TForm1.Btn_Hide_Show_PanelsClick(Sender: TObject);
begin
 // who will be the first... or last = visible?
  for var i: integer := 0 to (Form1.ComponentCount - 1) do
    if Form1.Components[i] is TPanel then
      TPanel(Form1.Components[i]).Visible := not TPanel(Form1.Components[i]).Visible;
end;

procedure TForm1.Btn_Show_Hide_PanelONEClick(Sender: TObject);
begin
 // nothing should be change here! stay where was defined!
  Panel1.Visible := not Panel1.Visible;
end;

all aligned on "Left": 2,3,4,5,6

image.png.33d6b987d021c71557c46219ae878b0c.png     Project1_q0ZlcpKc1I.gif

Edited by programmerdelphi2k

Share this post


Link to post

The problem with the "FlowPanel" is precisely the "flow of controls inside it"... Try placing the 5 panels above (left aligned) and resizing the "FlowPanel" to different sizes, including changing the "FlowStyle" to whatever others...

 

First, you may not be able to keep all the sub-panels left-aligned (like the sample above), as the "FlowPanel" will have its own alignment rule! So the "Align" property of the sub-panels will have no effect!

 

 

bds_fKXjkriXO9.gif

Share this post


Link to post
On 3/12/2023 at 4:48 PM, programmerdelphi2k said:

The problem with the "FlowPanel" is precisely the "flow of controls inside it"... Try placing the 5 panels above (left aligned) and resizing the "FlowPanel" to different sizes, including changing the "FlowStyle" to whatever others...

 

First, you may not be able to keep all the sub-panels left-aligned (like the sample above), as the "FlowPanel" will have its own alignment rule! So the "Align" property of the sub-panels will have no effect!

 

 

bds_fKXjkriXO9.gif

With the Flow Panel, you use the ControlIndex property to set the order. And the FlowStyle to manage orientation.  Your original question was about what happens to order when you hide and restore elements. The Flow Panel can resolve that. Alternately, you can achieve the results by setting the Tag property of each control on the panel and managing the order in code. I have done it both ways. The Flow Panel is easier, by far.

Share this post


Link to post

Try dropping a ControlwithmarginsSet.AlignWithMargins :.= True and see what happens!

 

// the margin property isn't just for making porting to Lazarus a chore. :classic_biggrin: 

Share this post


Link to post

really, I dont see "ControlIndex" helping in this task...  try expand/colapse the "FlowPanel" as my sample above and see the real resulted... 😩 no no no!

now, if you need just "hide/show" then, any other "container with many panels" do it, not? (be Panel, FlowPanel, Rectangles, etc...

Share this post


Link to post
13 minutes ago, programmerdelphi2k said:

really, I dont see "ControlIndex" helping in this task...  try expand/colapse the "FlowPanel" as my sample above and see the real resulted... 😩 no no no!

now, if you need just "hide/show" then, any other "container with many panels" do it, not? (be Panel, FlowPanel, Rectangles, etc...

And if you are correct, then the ultimate solution lies in coding.

Share this post


Link to post

I think that my first sample it's good and simple, just using basic idea with "obj containers". 

Using "FlowPanel", it's not so wrong... but I think that "it" it's not for this tasks... but if OP want more coding then both would can do it! (not necessary so easy using FlowPanel)

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×