Working with Autosize Form

Asked

Viewed 633 times

1

I’ve got a hot guy with the property Autosize = True, and two Groupbox One in the middle and one in the bottom. There is a function that makes the bottom Groupbox invisible if it is visible and vice versa, and since the Autosize property of the Form is equal to True the same auto adjusts and displays only the area in which the middle Groupbox is found if the Groupbox of the footer is invisible(Visible=False) and show it again in case it becomes 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 2 Groupbox appearing, when I change the Visible property of the Groupbox footer to False it disappears and the form adjusts itself, but if I change the property Visible to True nothing happens. Form does not auto-adjust to display the footer Groupbox.
If the Autosize of the focase is equal to False everything happens normally.
Is there any way to solve this problem without changing the Autosize property of the form to False and without changing the Align property of the Groupbox from the footer to Alcustom?

1 answer

3


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.
  • 2

    Thank you very much @Filipe.Fonseca, decided. I was breaking my head here. Very simple!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.