我的应用程序基于 MainForm、DetailForms 和 DialogForms。在任务栏上,我可以看到 MainFormButton 和 DetailForms。因此我使用:
procedure <DetailForm>.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent:= GetDesktopWindow;
end;
我使用delphi 2010,并且设置了 Application.MainFormOnTaskbar:= True; 当我在 Detailform 中使用 PromptForFileName 或 TSaveDialog 时,DetailForm 将位于 Mainform 后面。DetailForm 在关闭对话框后返回。
当我使用 DialogForm(带有属性 PopupMode: pmAuto 的 TForm 的 Showmodal)时,我的 DetailForm 将停留在主对话框和对话框之间。如何强制 TSaveDialog 像具有属性 PopupMode: pmAuto 的 showmodal 或如何防止我的 detailform 落后于 mainform
演示:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, ActnList;
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);
var
oForm: TForm;
begin
oForm:= Unit2.TForm2.Create(Self);
oForm.Show;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
SaveDialog1: TSaveDialog;
procedure cxButton1Click(Sender: TObject);
private
protected
procedure CreateParams(var Params: TCreateParams); override;
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent:= 0; // --> Testing
end;
procedure TForm2.cxButton1Click(Sender: TObject);
begin
self.SaveDialog1.execute();
end;
end.