窗体的隐藏与恢复!!! ( 积分: 100 )

  • 主题发起人 主题发起人 灵魂独舞
  • 开始时间 开始时间

灵魂独舞

Unregistered / Unconfirmed
GUEST, unregistred user!
application.CreateForm(tjiaofeiform,jiaofeiform);
jiaofeiform.ShowModal;
jiaofeiform.Free;
用这种方式建立窗体
在进入新窗体jiaofeiform后,用hide将原窗体隐藏
当关闭jiaofeiform时,用show将原窗体还原
却发现原窗体不可用(连关闭都关不了),怎么回事?
 
application.CreateForm(tjiaofeiform,jiaofeiform);
jiaofeiform.ShowModal;
jiaofeiform.Free;
用这种方式建立窗体
在进入新窗体jiaofeiform后,用hide将原窗体隐藏
当关闭jiaofeiform时,用show将原窗体还原
却发现原窗体不可用(连关闭都关不了),怎么回事?
 
// 我测试过, 你的要求是可以完成的,
// 估计你在引用的时候, 窗口(form)变量的传递有问题,
// 如果还是测试不通, 可以将你的整个测试工程(全部代码)发送给我,我帮你看看
// 我的邮件地址: xlx_obt@163.com


// project 代码
//----------------------------------------------------------------

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
// Application.CreateForm(TForm2, Form2);
Application.Run;
end.


// 主窗口代码
//----------------------------------------------------------------
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
hide; // 隐藏主窗口
application.CreateForm(TForm2, form2);
form2.ShowModal ;
form2.Free ;
end;

end.


// form2 代码
//-------------------------------------------------------------------
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, 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

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
form1.show; // 显示主窗口
close; // 关闭本窗口
end;

end.
 
在现实窗口的时候,最好确认以下Application.Handle这个HWND(也是一个窗口)的状态。可以通过ShowWindow/Application.Restore等等来控制。
如果在Application.Handle处于最小化,然后通过ShowWindow显示一个窗口,就会导致此问题.如果此时你在任务条右键此应用,然后选择恢复,之后可以正常操作的话,那么很肯定就是我所说的.
 
路过,学习了。。。
 
将代码贴上
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
application.CreateForm(tform2,form2);
form2.ShowModal;
form2.Free;
end;
end.

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QRPrntr, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1,unit4;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
application.CreateForm(tform4,form4);
form4.QuickRep1.Preview;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
form1.Hide;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.Show;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;
end.

unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, StdCtrls, QRPrntr;
type
TForm3 = class(TForm)
QRPreview1: TQRPreview;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses unit2;
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
form2.Hide;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form2.Show;
end;
end.

unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt;
type
TForm4 = class(TForm)
QuickRep1: TQuickRep;
procedure QuickRep1Preview(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses unit3;
{$R *.dfm}
procedure TForm4.QuickRep1Preview(Sender: TObject);
begin
form3.qrpreview1.QRPrinter:=quickrep1.QRPrinter;
form3.Show;
end;
end.
其中用到了quickreport
form1.button1调出打印窗体form2;
form2.button1调出预览窗体form3,form3中的QRPreview1对form4中的QuickRep1内容进行预览.
问题出在预览后用form3.button1退出,将隐藏的form2恢复显示时,form2不可用!!!
 
赞成zjan521而且也比较好.我一般也是这样做的。
 
对,取Handle然后对Handle进行操作就可以了.
 
后退
顶部