【发布时间】:2011-07-20 17:44:00
【问题描述】:
总结:
请参阅下方来自 Craig 和 Sertac 的有用 cmets。
================================================ =======
如以下最小化代码所示,TForm10 设置为fsStayOnTop。 TForm10.btnTryDlgClick 调用dlgOpen1.Execute,显示的对话框如预期的那样。但是,当我在TForm10.btnTryFormClick 中调用TForm11.Create(Self).ShowModal 时,表单隐藏在TForm10 后面。我想知道如何理解这种行为,为什么标准 TOpenDialog 可以按预期显示?任何意见表示赞赏!
PS:一种解决方法是覆盖 TForm11 的 CreateParams 过程,并将 Params.wndParent 设置为 0。但在我看来,使用此解决方法会破坏窗口层次结构。
procedure TForm11.CreateParams(var Params: TCreateParams); // override;
begin
inherited;
params.wndParent := 0;
end;
PS:Remy 在以下相关 SO 页面中提到了另一种解决方法:setting the modal Form's PopupParent property to be the StayOnTop Form。但在随后的 cmets 中,Sertac 提到这种变通方法也会破坏窗口层次结构。
PS:可能相关的 SO 页面:
Modal forms hidden by fsStayOnTop forms
How Can I Keep the FindDialog from Staying on Top (Delphi)?
How to make sure a dialog is always front of the main window
Form is hidden behind other forms when ShowModal is called
Make 2 forms able to overlap each other?
Multiple form Delphi applications and dialogs
@ 987654327@
Delphi - How to prevent Forms/MsgBoxes to move under prior form?
How to allow Delphi secondary forms behind the main form
Fake modal dialog using Show?
Delphi MainFormOnTaskBar Modal windows bug
Unit10 的来源:
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm10 = class(TForm)
btnTryDlg: TButton;
dlgOpen1: TOpenDialog;
btnTryForm: TButton;
procedure FormCreate(Sender: TObject);
procedure btnTryDlgClick(Sender: TObject);
procedure btnTryFormClick(Sender: TObject);
end;
var
Form10: TForm10;
implementation
{$R *.dfm}
uses
Unit11;
procedure TForm10.FormCreate(Sender: TObject);
begin
FormStyle := fsStayOnTop;
end;
procedure TForm10.btnTryDlgClick(Sender: TObject);
begin
dlgOpen1.Execute;
// dlgOpen1.Execute(Self.Handle);
end;
procedure TForm10.btnTryFormClick(Sender: TObject);
begin
TForm11.Create(Self).ShowModal;
end;
end.
Unit10 的 DFM:
object Form10: TForm10
Left = 0
Top = 0
Caption = 'Form10'
ClientHeight = 255
ClientWidth = 414
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object btnTryDlg: TButton
Left = 32
Top = 24
Width = 153
Height = 201
Caption = 'Try dialog'
TabOrder = 0
OnClick = btnTryDlgClick
end
object btnTryForm: TButton
Left = 224
Top = 24
Width = 153
Height = 201
Caption = 'btnTryForm'
TabOrder = 1
OnClick = btnTryFormClick
end
object dlgOpen1: TOpenDialog
Left = 96
Top = 168
end
end
Unit11 的来源:
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm11 = class(TForm)
end;
implementation
{$R *.dfm}
end.
Unit11 的 DFM:
object Form11: TForm11
Left = 0
Top = 0
Caption = 'Form11'
ClientHeight = 183
ClientWidth = 203
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
end
【问题讨论】:
-
Xichen - question you refer 的不同之处在于,模态表单是从
fsNormal表单启动的,而应用程序中还有另一个fsStayOnTop表单。在那个问题中,如果您将模态表单的 PopupParent 设置为顶层表单,它将显然由顶层表单拥有,但它应该由根据应用程序设计启动它的表单拥有。这就是我所说的打破等级制度的意思。 -
顺便说一句,我复制粘贴了您的代码,无法复制问题,当我单击 btnTryForm 时,模态表单在 Form10 上方。 +1 链接集合(研究)虽然..
-
@Sertac:非常感谢您抽出宝贵的时间和对
window hierarchy提供帮助的cmets!关于目前的问题,很抱歉无法复制。 “它在我的机器上works...”O_O -
我也为研究工作+1。
标签: delphi forms dialog modal-dialog stayontop