Working with AutoSize Form

1

I have a form with the property AutoSize = True , and two GroupBox one in the middle and another in the footer. There is a function that makes the GroupBox below invisible if it is visible and vice versa, and since the AutoSize property of the Form is equal to True it auto adjusts and only displays the area where the GroupBox in the middle is found if the GroupBox the footer is invisible ( Visible = False ) and returns to show if it is visible again ( Visible = True ). So far so good.
But if I set the GroupBox property that is in the footer as AlBottom this does not occur. The Form starts with the GroupBox 2 appearing, when I change the GroupBox's Visible property from the footer to False it disappears and the form auto adjusts, however if I change the Visible property to True nothing happens . The Form does not auto fit to display the GroupBox's footer. If the form's AutoSize equals False everything happens normally . Is there any way to work around this problem without changing the AutoSize property of the form to False and without changing the GroupBox Align property of the footer to AlCustom?

    
asked by anonymous 04.06.2014 / 15:57

1 answer

3

Do the opposite.

If you make an align top stack, the form will respect the original order.

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.
    
04.06.2014 / 16:16