问题是:如何在应用程序最小化时隐藏其他表单,因为恢复应用后,其他表单无法关闭。附件代码显示了行为。首先,我按按钮打开其他表格。它设置了表单样式设置fsstayontop。然后,我按计时器按钮并最大程度地减少主形式。计时器还原形式后,无法关闭另一个。
program MINIBUG;
uses
Vcl.Forms,
MainForm in 'MainForm.pas' {Form7},
AddForm in 'AddForm.pas' {Form8};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm7, Form7);
Application.CreateForm(TForm8, Form8);
Application.Run;
end.
unit AddForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm8 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form8: TForm8;
implementation
{$R *.dfm}
end.
unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AddForm, Vcl.ExtCtrls;
type
TForm7 = class(TForm)
btnAddForm: TButton;
tmr1: TTimer;
Button1: TButton;
procedure btnAddFormClick(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
implementation
{$R *.dfm}
procedure TForm7.btnAddFormClick(Sender: TObject);
begin
Form8.Show;
end;
procedure TForm7.Button1Click(Sender: TObject);
begin
tmr1.Enabled := True;
end;
procedure TForm7.tmr1Timer(Sender: TObject);
begin
tmr1.Enabled := False;
form8.Close;
Application.Restore;
end;
end.
testcase错误?
我不确定您的测试案例是否正确。如果计时器事件模拟了对关联文件的双重销售的行为,为什么会导致Form8.Close
操作?您说的是,问题的一部分是在打开关联的文件时,附加表格变得可见(与主表单一起),因此,当您启动计时器时,隐藏(Form.Hide
)应发生,并且在OnTimer
时应进行。显示(`form.show)。
答案
无论如何,当应用程序最小化时,如何隐藏您实际问题的答案是您不必做任何特别的事情。附加表格也将被隐藏,而无需采取任何操作。
如果您出于某种原因需要或必须主动隐藏其他表格,请通过在主表单中添加TApplicationEvents
组件来进行此操作,然后使用其OnMinimize
事件来调用Form8.Hide
和OnRestore
事件来调用Form8.Show
。
也考虑
顺便说一句,如果您选择Form.Close
或Form.Hide
有区别。关闭通过一个过程来调用CloseQuery()
,而隐藏只需设置Visible
属性yo False
。