我原以为一种方法是使用“幕后”主要形式,它仅用于以下目的:
选择并显示其他表单之一作为主要表单,然后像老式的“flash”屏幕一样永久隐藏自身(Visible:=FALSE)。
当它选择作为主窗体的窗体关闭时充当应用程序终止器(只需连接适当的 OnClose 事件)。
代表指定的伪主窗体打开其他窗体,使得隐藏的真正主窗体是其他窗体的“所有者”,而不是“伪主窗体”。如果您的所有其他表单都具有“非”弹出式样式并且通过 Show 调用而不是 ShowModal 可见,这似乎无论如何都会发生。
这种对应用程序行为的小规模重组可能会为您提供您正在寻找的那种用户交互。
unit FlashForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TFlash = class(TForm)
lblTitle: TLabel;
lblCopyright: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
public
procedure CloseApp;
end;
var
Flash: TFlash;
implementation
{$R *.dfm}
uses Main;
procedure TFlash.CloseApp; // Call this from the Main.Form1.OnClose or CanClose (OnFormCloseQuery) event handlers
begin
close
end;
procedure TFlash.FormCreate(Sender: TObject); // You can get rid of the standard border icons if you want to
begin
lblCopyright.Caption := 'Copyright (c) 2016 AT Software Engineering Ltd';
Refresh;
Show;
BringToFront;
end;
procedure TFlash.Timer1Timer(Sender: TObject);
begin
Application.MainFormOnTaskBar := FALSE; // This keeps the taskbar icon alive
if assigned(Main.MainForm) then
begin
visible := FALSE;
Main.MainForm.Show;
Timer1.Enabled := FALSE;
end else Timer1.Interval := 10; // The initial time is longer than this (flash showing time)
end;
end.
// Finally, make this the FIRST form created by the application in the project file.