2017-09-05 24 views
-1

问题是:如何在应用程序最小化时隐藏其他表单,因为应用程序恢复后无法关闭其他表单。附加的代码显示行为。首先我按下按钮打开其他表格。它设置了窗体样式集fsStayOnTop。然后我按下定时器按钮并最小化主窗体。定时器恢复表单后,额外的一个不能关闭。Delphi XE2:通过在Windows中打开文件来最小化应用程序还原

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. 
+1

恐怕您没有向我们提供足够的必要信息来帮助您解决问题。您遗漏的最重要的信息是在您双击应用程序设置为打开的文件后执行的代码。我猜测这个问题实际上可能在于这个代码。 – SilverWarior

+2

提供一个[mcve] –

+0

我现在可以重现您使用所提供的代码描述的问题。我明白这只是模仿真实情况。因此,请解释“OnTimer”事件中'form8.Close;'的真实世界行为正在复制。如果这条线被删减了,没有问题。 –

回答

0

Testcase error?

我不确定你的测试用例是否正确。如果计时器事件模拟双击相关文件的行为,为什么会导致Form8.Close操作?你说,问题的一部分是,当打开相关文件时,附加表单变得可见(与主表单一起),所以隐藏(Form.Hide)应该在启动计时器时发生,并且在OnTimer表单应该被显示(`Form.Show)。

回答

无论如何,回答您的实际问题,如何隐藏其他表单应用程序时,最大限度地减少是你没有做什么特别的。额外的表单也会隐藏起来,而不会采取任何行动。

如果您由于某种原因希望或必须积极隐藏其他形式,加入了TApplicationEvents组件添加到您的主要形式做到这一点,并使用其OnMinimize事件调用Form8.HideOnRestore事件调用Form8.Show

还要考虑

顺便说一句,是有区别的,如果你选择Form.CloseForm.Hide。关闭通过程序呼叫CloseQuery()而隐藏只需设置Visible财产哟False

相关问题