delphi高手看过来,窗口调用的问题!
请教各位大虾,小弟,正在学习delphi...遇到一个问题,比如说我想用两个窗口,分别在上面放置一个按钮,程序运行的时候,点form1上的button,马上就把form2...
请教各位大虾,小弟,正在学习delphi...
遇到一个问题,比如说我想用两个窗口,分别在上面放置一个按钮,程序运行的时候,点form1上的button,马上就把form2显示出来,点form2上的button又回到form1,请大虾们指点也下小弟吧! 展开
遇到一个问题,比如说我想用两个窗口,分别在上面放置一个按钮,程序运行的时候,点form1上的button,马上就把form2显示出来,点form2上的button又回到form1,请大虾们指点也下小弟吧! 展开
展开全部
这个问题...如果是简单的两个窗体之间的显示隐藏,可以这样做(主窗体为form1):
在unit1中,添加unit2单元,在这里:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,unit2{你的form2单元名称}, StdCtrls;
button下的代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.Show;
form1.Hide;//控制form2显示时,form1是否隐藏
end;
在unit2中,也需要添加对unit1的引用,不过不可以在uses直接添加了,需要在实现部分添加:
var
Form2: TForm2;
implementation
uses unit1;//在次添加对form1单元的引用.
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);//form2中,button下的代码:
begin
form2.Close;
form1.Show;
end;
就是这么简答.
如果你是想做系统的登陆窗体,可以到我的空间里去看看这么做登陆模块:
http://hi.baidu.com/yueyun889/blog/item/e302a93ea999a2fa838b13e3.html
在unit1中,添加unit2单元,在这里:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,unit2{你的form2单元名称}, StdCtrls;
button下的代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.Show;
form1.Hide;//控制form2显示时,form1是否隐藏
end;
在unit2中,也需要添加对unit1的引用,不过不可以在uses直接添加了,需要在实现部分添加:
var
Form2: TForm2;
implementation
uses unit1;//在次添加对form1单元的引用.
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);//form2中,button下的代码:
begin
form2.Close;
form1.Show;
end;
就是这么简答.
如果你是想做系统的登陆窗体,可以到我的空间里去看看这么做登陆模块:
http://hi.baidu.com/yueyun889/blog/item/e302a93ea999a2fa838b13e3.html
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if form2=nil then
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(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
action:=cafree;
form2:=nil;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
close;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if form2=nil then
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(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
action:=cafree;
form2:=nil;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
close;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
form1上button的click事件:
form2:=tform2.create(application);
form2.showmodal;
form2.free;
form2上button的click事件:
close;
easy~!
form2:=tform2.create(application);
form2.showmodal;
form2.free;
form2上button的click事件:
close;
easy~!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询