现在基本都是在做FMX运用,最近一个项目本来也是用FMX来做,但是在做初步规划的时候发现,FMX比较麻烦,因为要和下位机通信,并且实时显示下位机送上来的数据(SOCKET通信,各种传感器的数据),波形图显示方面的控件,FMX下没找到好用的,VCL下倒是有IOCOM等工控控件可以用。决定还是用VCL来做,而且也只在WINDOWS下运用。
搞习惯了FMX的界面布局,在VCL没有LAYOUT控件真感觉不方便啊。
回到正题,在一个ShowModal窗体上再弹出ShowModal窗体,如果这个窗体不是需要满屏显示的话,一般也没什么问题。
今天在测试的时候,在一个满屏显示ShowModal窗体上再弹出一个满屏显示的ShowModal窗体,发现再弹出的窗体不会满屏显示了,已经设置窗体的
WindowState := TWindowState.wsMaximized;
然后设置窗体Align := alClient, 可以满屏显示了,但是弹出这个窗体的父窗体的一些控件竟然会显示出来,肯定是Z-Order出问题了。
网上搜了下,说是要设置窗体的PopupMode和PopupParent,也忘了这俩属性是干嘛的。看文档,这俩属性都是和Z-Order有关的,
Vcl.Forms.TForm.PopupMode
Controls how the top-level form behaves with respect to Window's WS_POPUP style.
The PopupMode property controls how the top-level form behaves with respect to Window's WS_POPUP style. A window that has the WS_POPUP style is always above its "owner" in Z-order. You can use the PopupMode property in conjunction with the PopupParent property to avoid the appearance of a hung application caused by a modal dialog showing up behind another form on the screen.
Note: Using the
PopupMode property is similar to specifying
fsStayOnTop
for the
FormStyle property, but allows better control over the layering.
The PopupMode property is automatically set to pmAuto
when the ShowModal method is called. However, this causes the window handle to be recreated, which is not usually desirable. To avoid the re-creation of window handles, you can explicitly set the PopupMode property to pmAuto
prior to calling the ShowModal method (such as at design time).
Set the PopupMode property to pmExplicit
for non-modal design windows such as tool palettes and other floating tool windows. This causes the windows to always remain on top of the main form. In the case of a snapped together design (in which the window is docked to the main form), the design window remains on top of the designer.
Note: For undocked windows, the design window remains above the main form, allowing other top-level forms to obscure the design window.
Set the PopupMode property to pmNone
if you want the pop-up window to have the pre-Delphi 8 behavior (except for the ShowModal item mentioned above).
You can force the Z-Ordering of your forms and create a "stacked" appearance that the user cannot change by setting the PopupParent property to an explicit TCustomForm. If the PopupMode property is pmExplicit
and PopupParent is nil, then the Application.MainForm is implicitly used as the PopupParent. If no Application.MainForm is assigned, then Application.Handle is used as the PopupParent. If the PopupMode property is set to pmAuto
, Screen.ActiveForm is used as the PopupParent.
按说明设置了,但是没啥用。。。。
窗体是继承自通用的自定义窗体的,祖先窗体设置了Position := poScreenCenter。因为这个自定义祖先窗体是无边框的,主要用于非满屏显示的ShowModal窗体,
设置Position := poDefault,没想到可以正常满屏显示了。。。。
其它窗体属性(Align, PopupMode, PopupParent)都不用改,就默认的。只要Position := poDefault,然后设置WindowState := wsMaximized 就可以。
估计以前肯定也遇到这问题,没记录下来。