Do the opposite.
If you make a stack of top align, the form will respect the original order.
Follow sources:
(to adapt dfm, right click on the form, view as text)
DFM:
object Form1: TForm1
Left = 0
Top = 0
AutoSize = True
Caption = 'Form1'
ClientHeight = 433
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object GroupBox1: TGroupBox
Left = 0
Top = 41
Width = 635
Height = 177
Align = alTop
Caption = 'GroupBox1'
TabOrder = 0
ExplicitLeft = -8
ExplicitTop = 8
object Button1: TButton
Left = 48
Top = 48
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 635
Height = 41
Align = alTop
Caption = 'Panel1'
TabOrder = 1
ExplicitLeft = -8
ExplicitTop = 1
object Button3: TButton
Left = 72
Top = 10
Width = 75
Height = 25
Caption = 'Button3'
TabOrder = 0
OnClick = Button3Click
end
end
object GroupBox2: TGroupBox
Left = 0
Top = 218
Width = 635
Height = 215
Align = alTop
Caption = 'GroupBox2'
TabOrder = 2
ExplicitLeft = -8
ExplicitTop = 256
object Button2: TButton
Left = 48
Top = 48
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button2Click
end
end
end
PAS:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if GroupBox2.Visible then
GroupBox2.Visible := false
else
GroupBox2.Visible := true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if GroupBox1.Visible then
GroupBox1.Visible := false
else
GroupBox1.Visible := true;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if GroupBox2.Visible then
GroupBox2.Visible := false
else
GroupBox2.Visible := true;
end;
end.
Thank you very much @Filipe.Fonseca, decided. I was breaking my head here. Very simple!
– wesley luan