Dave Craggs 7 Posted March 10, 2023 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
Dave Craggs 7 Posted March 10, 2023 Hmm - could I do something with the Left property maybe? Share this post Link to post
Dave Craggs 7 Posted March 10, 2023 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
aehimself 399 Posted March 10, 2023 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
Uwe Raabe 2064 Posted March 10, 2023 (edited) Another answer can be found on StackOverflow (although for alTop) Delphi: How to programmatically adjust visual ordering of components with align = alTop Edited March 10, 2023 by Uwe Raabe Share this post Link to post
programmerdelphi2k 237 Posted March 10, 2023 (edited) 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 Edited March 10, 2023 by programmerdelphi2k Share this post Link to post
Bill Meyer 337 Posted March 12, 2023 Is there a reason you can't use a FlowPanel? Share this post Link to post
programmerdelphi2k 237 Posted March 12, 2023 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! Share this post Link to post
Bill Meyer 337 Posted March 15, 2023 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! 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
Pat Foley 52 Posted March 15, 2023 Try dropping a ControlwithmarginsSet.AlignWithMargins :.= True and see what happens! // the margin property isn't just for making porting to Lazarus a chore. Share this post Link to post
programmerdelphi2k 237 Posted March 16, 2023 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
Bill Meyer 337 Posted March 16, 2023 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
programmerdelphi2k 237 Posted March 16, 2023 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