How to allow Delphi secondary forms behind the main form

前端 未结 3 1504
予麋鹿
予麋鹿 2020-12-18 07:42

If in Delphi 2010 or XE Application.MainFormOnTaskbar is set to true then all secondary forms are always in front of the main window. It does not matter what the Popupmode o

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 08:08

    I would have thought that one approach would be to have a "behind-the-scenes" main form which serves only the following purposes:

    1. To select and show one of the other forms as the main form and then perpetually hide itself (Visible:=FALSE) like the good old-fashioned "flash" screens.

    2. To act as an application terminator when the form it selected as the main form is closed (just wire the appropriate OnClose events).

    3. To open other forms on behalf of the designated pseudo-main-form such that the hidden real main form is the "owner" of the other forms, not the "pseudo-main-form". It appears that this will happen anyway if all your other forms have a 'non' pop-up style and are visible via Show calls rather than ShowModal.

    This small restructuring of the application's behavior may then get you the kind user interaction that you are looking for.

    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.
    

提交回复
热议问题