Recent

Author Topic: [SOLVED] TScrollBox and panel order  (Read 1206 times)

superc

  • Sr. Member
  • ****
  • Posts: 251
[SOLVED] TScrollBox and panel order
« on: April 12, 2023, 02:17:15 pm »
Hello,

I have a perhaps stupid problem but I can't solve it: I have a TScrollBox with 'alTop' aligned panels inside; I put them in a specific order but now they are all messed up: how can I order them the way I want? thank you in advance
« Last Edit: April 13, 2023, 09:32:04 am by superc »

balazsszekely

  • Guest
Re: TScrollBox and panel order
« Reply #1 on: April 12, 2023, 02:57:25 pm »
Hello,

I have a perhaps stupid problem but I can't solve it: I have a TScrollBox with 'alTop' aligned panels inside; I put them in a specific order but now they are all messed up: how can I order them the way I want? thank you in advance
At design time just drag drop each panel to its place.
At runtime try something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3. begin
  4.   for I := 0 to ScrollBox1.ControlCount - 1 do
  5.     if (ScrollBox1.Controls[I] is TPanel) then
  6.       (ScrollBox1.Controls[I] as TPanel).Align := alNone;
  7.  
  8.  
  9.   for I := 0 to ScrollBox1.ControlCount - 1 do
  10.   begin
  11.     if (ScrollBox1.Controls[I] is TPanel) then
  12.     begin
  13.       (ScrollBox1.Controls[I] as TPanel).Align := alTop;
  14.       (ScrollBox1.Controls[I] as TPanel).Top := (ScrollBox1.Controls[I] as TPanel).Tag*((ScrollBox1.Controls[I] as TPanel).Height + 1);
  15.     end;
  16.   end;
  17. end;

See attached project for more details.
« Last Edit: April 12, 2023, 03:56:01 pm by GetMem »

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: TScrollBox and panel order
« Reply #2 on: April 12, 2023, 04:36:08 pm »
Hello,

I have a perhaps stupid problem but I can't solve it: I have a TScrollBox with 'alTop' aligned panels inside; I put them in a specific order but now they are all messed up: how can I order them the way I want? thank you in advance
At design time just drag drop each panel to its place.
At runtime try something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3. begin
  4.   for I := 0 to ScrollBox1.ControlCount - 1 do
  5.     if (ScrollBox1.Controls[I] is TPanel) then
  6.       (ScrollBox1.Controls[I] as TPanel).Align := alNone;
  7.  
  8.  
  9.   for I := 0 to ScrollBox1.ControlCount - 1 do
  10.   begin
  11.     if (ScrollBox1.Controls[I] is TPanel) then
  12.     begin
  13.       (ScrollBox1.Controls[I] as TPanel).Align := alTop;
  14.       (ScrollBox1.Controls[I] as TPanel).Top := (ScrollBox1.Controls[I] as TPanel).Tag*((ScrollBox1.Controls[I] as TPanel).Height + 1);
  15.     end;
  16.   end;
  17. end;

See attached project for more details.
so to do a safe and precise sorting I have to assign a tag... right?


KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: TScrollBox and panel order
« Reply #3 on: April 12, 2023, 05:08:19 pm »
I have not tried wp's way of doing, I am kinda do the same except that my "Top" is just increasing by 1 for each element.
Exemplary:
Code: Pascal  [Select][+][-]
  1. (ScrollBox1.Controls[I] as TPanel).Top := Succ(i);
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

balazsszekely

  • Guest
Re: TScrollBox and panel order
« Reply #4 on: April 12, 2023, 05:11:11 pm »
@superc
Quote
so to do a safe and precise sorting I have to assign a tag... right? 
Yes.

 

TinyPortal © 2005-2018