Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Expanding form

Hi
How can I have a form can be expand ?
I want a form like some messages have.  On the form I have a message, plus a button, if the user click the button, the form expand at the bottom for more details.
I know I can have a form with two panel, when I click the button, the bottom panel is visible or not.  But it dosn't have a nice apparence.  With that solution, the top panel is resized, and I do not want that.
How can I do that ?
Thanks
0
frdep
Asked:
frdep
  • 2
1 Solution
 
TheRealLokiSenior DeveloperCommented:
2 panels, the top panel (with buttons, etc) has its align property set to alTop.
the bottom (with message) has align property set to alClient
put your TMemo or whatever in the bottom panel and set its align property to tlClient also
(you can actually just have 1 top panel, and a TMemo below, but the panel is a nic option if you want other controls in there)
now all you have to do is resize your form and the message are resizes too

e.g.
procedure TForm1.Button1Click(sender:TObject);
begin
    Form1.height := 600; // was 200
end;

another option is to use a TScrollbox so your form doesn't expand, but you end up with scrollbars
0
 
Ivanov_GCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  Height_Expanded  = 400;
  Height_Collapsed = 200;

type
  TExpandableForm = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    // flag to track if the form was expanded
    Is_Expanded    : Boolean;
  public
    { Public declarations }
  end;

var
  ExpandableForm: TExpandableForm;

implementation

{$R *.dfm}

procedure TExpandableForm.FormCreate(Sender: TObject);
begin
  // create form in normal size
  Self.Height := Height_Collapsed;
  Is_Expanded := False;
end;

procedure TExpandableForm.Button1Click(Sender: TObject);
begin
  Is_Expanded := not Is_Expanded;
  if Is_Expanded then
    Self.Height := Height_Expanded
  else
    Self.Height := Height_Collapsed;
end;

end.
0
 
calinutzCommented:
Do not forget to modify the code of Ivanov G making all the controls that appear in the expanded part of the form :invisible. Or else a scrollbar will appear on your form making it look ugly.
  It's a different story if you want to create the components on runtime in the onExpand part of the code, then you don't need to make them invisible.
Of course in the On Expand part you must make them visible again.
Something like (considering the above code)


procedure TExpandableForm.FormCreate(Sender: TObject);
begin
  // create form in normal size
  Self.Height := Height_Collapsed;
  Is_Expanded := False;
  Panel1.Visible:=false;   //this is considering that you placed a panel on the expandable part of the form

end;

procedure TExpandableForm.Button1Click(Sender: TObject);
begin
  Is_Expanded := not Is_Expanded;
  if Is_Expanded then
   begin
    Self.Height := Height_Expanded;
    Panel1.Visible:=true;   //this is considering that you placed a panel on the expandable part of the form
  end
  else
  begin
    Self.Height := Height_Collapsed;
    Panel1.Visible:=false;   //this is considering that you placed a panel on the expandable part of the form
  end

end;

Cheers :)
0
 
Ivanov_GCommented:
calinutz, good point. Simplier solution will be to place the controls on the form and disable the Scrollbars. You will not need a Panel.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now