效果图
新建窗体
窗体的显现
procedure TForm2.btn2Click(Sender: TObject);
begin
Form1.Show;
Form2.Hide;
end;
第一个窗体完整代码
注意引用第二个窗体
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Dialogs, Forms,Form, Formprpt, StdCtrls;
type
TForm1 = class(MForm)
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2; //要加这个
{$R *.DFM}
procedure TForm1.btn1Click(Sender: TObject);
begin
//主窗体隐藏,第二个窗体显示
form1.Hide;
form2.show;
//展示输入的数据
Form2.lbl1.Caption:='您的姓名:'+edt1.Text;
Form2.lbl2.Caption:='所购商品:'+edt2.Text;
Form2.lbl3.Caption:='商品数量:'+edt3.Text;
end;
end.
第二个窗体完整代码
注意引用第一个窗体
unit Unit2;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Dialogs, Forms,Form, Formprpt, StdCtrls;
type
TForm2 = class(MForm)
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1; // 引用第一个窗体
{$R *.DFM}
procedure TForm2.btn1Click(Sender: TObject);
begin
form1.close;
Form2.Close;
end;
procedure TForm2.btn2Click(Sender: TObject);
begin
Form1.Show;
Form2.Hide;
form1.edt1.Text:='';
form1.edt2.Text:='';
form1.edt3.Text:='';
end;
end.