Recent

Author Topic: [Worked around] Set a TPanel Z Order to a specific value  (Read 2135 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
[Worked around] Set a TPanel Z Order to a specific value
« on: September 21, 2014, 04:23:36 pm »
I know the long way to change a panel's z-order to what I want.  Enumerate over all controls, calling SendToBack or BringToFront in just the right order.   But that's messy, and today I'm chasing elegant (Sunday best and all that) :-)

Is there a simple way of setting the Z-Order of a TPanel so it's directly above another TPanel without mucking around with every other related visible control?  (Both Panels have the same parent - oh - it's another Panel, let call it PanelParent :-) )

I've got this far on my own, and yeah, it's working.   But my problem is I don't know how to retrieve the current Z-Order of Panel1...

Code: [Select]
Type
  THackPanel = Class(TPanel)
  end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  THackPanel(PanelParent).SetChildZPosition(Panel2, 0);
  //THackPanel(PanelParent).SetChildZPosition(Panel2, Panel1.ZOrder+1);  // <-- What I want...
end;

Alternatively, is there just a better way of doing this?
« Last Edit: September 21, 2014, 04:50:03 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Set a TPanel Z Order to a specific value
« Reply #1 on: September 21, 2014, 04:49:47 pm »
Actually - ignore this.  I've found a solution using BringToFront thats easy to read and works....  (not worth posting - relates to the classes in use)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018