开发者

How to make sure a dialog is always front of the main window

I have not yet found the best solution for this. I have a non modal dialog that can be opened in unlimited instances by a hotkey in the application. Even the dialog itself can open a new instance. I want those dialogs to always be front of the main application window. I have tried a couple of things.

  • Set FormStyle to fsStayOntop. This works but ha开发者_如何学Cve the advantage that the dialog will be front of ALL windows even other applications. I only want it to be front of my main window.
  • Set PopupMode to pmAuto. This also works except for the case when one dialog open another dialog. If the first dialog is closed then it automatically close the second one. This is not acceptable.
  • Use the default properties for a form. As soon as the main window is clicked on the opened dialogs is behind the main window.

Any other suggestions :-)


From TCustomForm.PopupParent Property;

If the PopupMode property is set to pmExplicit and PopupParent is nil, then the Application.MainForm is implicitly used as the PopupParent

.


AFAIK Delphi 2007 support MainFormOnTaskbar feature. With

   Application.MainFormOnTaskbar := True;

in project source ANY application form (with default parent window) is shown above main form.


If you are unsure what form is the Main Form, go to Project/Options/Forms and set the correct Main Form. Another probable reason is that you are upgrading a project from a previous Delphi version so the project source does not contain the above line of code - add this line manually.


I think your first effort, fsstayontop, is the best option. The issue with displaying in front of other applications may be impossible to avoid since you are really using Windows function not something unique to Delphi.

As I recall it is possible to manually set the Z order, but that is tedious to impossible in most apps.

If your dialog is not so big as to hide other applications, it can be moved and users can still access the other apps without first interacting with your dialog. Seems not too bad.


You can try watching the OnHide event and immediately making the Visible flag to TRUE. This will probably cause flicker though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜