Prevent main form from appearing when showing anot

2019-05-14 21:43发布

问题:

I am trying to bring my secondary form to the Foreground, however when I do

MyForm.Show; // It may be hidden, therefore show it first
SetForegroundWindow(MyForm.Handle);

my Main Form appears aswell. The only way I can prevent that is to do MainForm.Hide; but I got to avoid that.

The idea is to have my secondary form appear on top of another application, without my Main Form having to do so as well.

回答1:

If you consider to make another application for this functionality, then you may also consider the following compromise: minimize the MainForm to the taskbar (rather than hiding it) to prevent it popping up when activating another form.

If so, then try this answer. It does add an extra icon to your taskbar for the secondary form, but I guess that'll be no problem since a different application would either. However, if the MainForm is nót minimized but obfuscated by other windows, activating the secondary form wíll also popup the MainForm, just like you are experiencing now.

And for the completeness of this answer's sake, but not by any means meant as advice: this answer describes a (somewhat experimental) construction to make fully independent windows. The little time I tested that solution, it seemed to work, but be prepared not counting any longer on the full/default functionality of the VCL.



回答2:

Try settings the state of the form to fsAlwaysOnTop.