Forms Delphi

Title: Smartly displaying a form in a panel.
Question: Have you ever wanted to have an application with multiple forms but instead of being a SDI or MDI you wanted the fact that you were using different forms to invisible to your users. This is the way to go. Show the forms inside a panel.
Answer:
I've listed the steps I took to get it right. Here they are.
- Start with a new Application
- Add a button and panel to Form1
- Add another form (Form2)
- Add a button to Form2
Set Form1.Panel1 properties to
BevelInner - bvLowered
BevelOuter - bvLowered
Caption -''
Set Form2 properities to
BorderIcons -biSys -False
-biMin-False
-biMax-False
-biHelp-False
BorderStyle -bsNone
Align -alClient
In the menu Project - Options
Removed Form2 from the Autocreate section.
I also had to add some code:
In Form1's unit17 Just after the implementation directive I added...
uses Unit18;
The Form1.Button1Click event should look something like this.
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(nil); // Instantiate the form
Form2.Parent := Panel1; // Who's your Daddy ?
Form2.Show; // Show me the money !
end;
And last but not least Form2's Button Click event :
procedure TForm2.Button1Click(Sender: TObject);
begin
Close ;
end;
This example should point you in the right direction. For all those Delphi Gurus out there who believe "If you can't cut and paste it's a waste" Here you go. If you'd like me to mail you the source, drop me a mail.
unit Unit17;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit18;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(nil);
Form2.Parent := Panel1;
Form2.Show;
end;
end.
unit Unit18;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
Close ;
end;
end.
Patrick Robinson
Senior Developer
Discovery Life Ltd
E-mail: patrickr@discoverylife.co.za
Greets fly out to GreenAlien,IceMan,Cromex,Spiderman,Hawk.
End of line ...