?
Solved

Expanding form

Posted on 2005-03-10
4
Medium Priority
?
248 Views
Last Modified: 2010-04-05
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
Comment
Question by:frdep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 13513591
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 13514507
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
 
LVL 11

Expert Comment

by:calinutz
ID: 13514872
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
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 500 total points
ID: 13516035
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question