unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
//实现由一个窗口切换到另一个窗口,而本窗口关闭
procedure TForm1.btn1Click(Sender: TObject);
begin
form2.show; //显示另一个窗口
form1.Hide; //本窗口关闭
end;
//上一个窗口不关闭,仍然显示
procedure TForm1.btn2Click(Sender: TObject);
begin
form2.show; //显示另一个窗口
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
btnNewForm: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnNewFormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.show; //回到原来的窗口
end;
//产生一个新窗口
procedure TForm2.btnNewFormClick(Sender: TObject);
begin
with TForm.Create(application) do
try
caption:='新窗口';
showmodal;
finally
free;
end;
end;
end.