FMX:模态形式不在顶部(Windows)
FMX: Modal forms not staying on top (Windows)
在某些情况下,本应是模态的表单或对话框没有保持在顶部。我正在使用 10.4 为 Windows 构建。这是一个涉及两个表单和一个 TSaveDialog 的简单示例。
重现问题:
- 运行 Windows
中的应用
- 单击显示 Window 按钮(您应该会看到 Form2)
- 单击“显示保存对话框”按钮(您应该会看到保存对话框)
- 单击不属于应用程序的另一个 window,例如资源管理器 window
- 单击 Form2。 Form1 现在将排在前面
如果您重复此操作但首先最大化 Form1,则用户在不从任务管理器关闭程序或使用一些专家 windows 知识的情况下不容易解决。
表格 1:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 480
ClientWidth = 640
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 264.000000000000000000
Position.Y = 168.000000000000000000
Size.Width = 97.000000000000000000
Size.Height = 33.000000000000000000
Size.PlatformDefault = False
Text = 'Show Window'
OnClick = Button1Click
end
end
表格 2:
object Form2: TForm2
Left = 0
Top = 0
Caption = 'Form2'
ClientHeight = 333
ClientWidth = 489
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 184.000000000000000000
Position.Y = 136.000000000000000000
Size.Width = 113.000000000000000000
Size.Height = 41.000000000000000000
Size.PlatformDefault = False
Text = 'Show Save Dialog'
OnClick = Button1Click
end
object SaveDialog1: TSaveDialog
Left = 80
Top = 40
end
end
Unit1:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, Unit2,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
end.
第 2 单元:
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.Button1Click(Sender: TObject);
begin
SaveDialog1.Execute;
end;
end.
我没有在 VCL 应用程序中看到这种行为(模态 windows 总是保持在最前面)。我还在 FMX 应用程序中看到了这个问题,其中的表单使用 ShowModal 显示,甚至消息 windows 使用 ShowMessage 创建。使用 TDialogServiceSync.ShowMessage 似乎有助于防止这种情况发生,但即便如此,一些用户也会遇到同样的问题。
为什么会发生这种情况,我能做些什么来解决这个问题?
您可以将 Form2
的 FormStyle
设置为 StayOnTop
FormStyle is one of the Normal, Popup, or StayOnTop values defined in TFormStyle.
Normal: Usual form. Such form can have the active state and support the z-order.
Popup: Such form cannot be active. All forms of this type belong to the PopupForms list.
StayOnTop: This form remains on top of the desktop and of other forms in the application, except any other form that also has FormStyle set to StayOnTop. If one StayOnTop form launches another, neither form will consistently remain on top.
https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Types.TFormStyle
尝试设置父项。
喜欢:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.parent := form1;
Form2.Show;
end;
我用这个得到了很好的结果,但在 OSX 它不起作用。
在某些情况下,本应是模态的表单或对话框没有保持在顶部。我正在使用 10.4 为 Windows 构建。这是一个涉及两个表单和一个 TSaveDialog 的简单示例。
重现问题:
- 运行 Windows 中的应用
- 单击显示 Window 按钮(您应该会看到 Form2)
- 单击“显示保存对话框”按钮(您应该会看到保存对话框)
- 单击不属于应用程序的另一个 window,例如资源管理器 window
- 单击 Form2。 Form1 现在将排在前面
如果您重复此操作但首先最大化 Form1,则用户在不从任务管理器关闭程序或使用一些专家 windows 知识的情况下不容易解决。
表格 1:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 480
ClientWidth = 640
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 264.000000000000000000
Position.Y = 168.000000000000000000
Size.Width = 97.000000000000000000
Size.Height = 33.000000000000000000
Size.PlatformDefault = False
Text = 'Show Window'
OnClick = Button1Click
end
end
表格 2:
object Form2: TForm2
Left = 0
Top = 0
Caption = 'Form2'
ClientHeight = 333
ClientWidth = 489
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 184.000000000000000000
Position.Y = 136.000000000000000000
Size.Width = 113.000000000000000000
Size.Height = 41.000000000000000000
Size.PlatformDefault = False
Text = 'Show Save Dialog'
OnClick = Button1Click
end
object SaveDialog1: TSaveDialog
Left = 80
Top = 40
end
end
Unit1:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, Unit2,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
end.
第 2 单元:
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.Button1Click(Sender: TObject);
begin
SaveDialog1.Execute;
end;
end.
我没有在 VCL 应用程序中看到这种行为(模态 windows 总是保持在最前面)。我还在 FMX 应用程序中看到了这个问题,其中的表单使用 ShowModal 显示,甚至消息 windows 使用 ShowMessage 创建。使用 TDialogServiceSync.ShowMessage 似乎有助于防止这种情况发生,但即便如此,一些用户也会遇到同样的问题。
为什么会发生这种情况,我能做些什么来解决这个问题?
您可以将 Form2
的 FormStyle
设置为 StayOnTop
FormStyle is one of the Normal, Popup, or StayOnTop values defined in TFormStyle.
Normal: Usual form. Such form can have the active state and support the z-order.
Popup: Such form cannot be active. All forms of this type belong to the PopupForms list.
StayOnTop: This form remains on top of the desktop and of other forms in the application, except any other form that also has FormStyle set to StayOnTop. If one StayOnTop form launches another, neither form will consistently remain on top.
https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Types.TFormStyle
尝试设置父项。
喜欢:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.parent := form1;
Form2.Show;
end;
我用这个得到了很好的结果,但在 OSX 它不起作用。