You cannot just say "the main window must remain in the background at all times". In some cases, it must not, otherwise it would be, in the pretty unlikely cases when you succeed, a direct violation of expected UI style. And remember that your application is not along on the desktop.
Your form can always stay on the back in Z-order relative to other forms in just two cases:
- All other forms are only shown in modal state via the call to
Form.ShowDialog
. This is not the most flexible solution; and overusing of those modal forms can become very irritating, but this is the most stable and legitimate design. Please see: https://msdn.microsoft.com/en-us/library/c7ykbedk(v=vs.110).aspx[^]. - All other forms could use always-on-top style, which is achieved using the property
Form.Topmost
. This solution can be recommended only in extremely rare cases. Please see: https://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost%28v=vs.110%29.aspx[^].
One of such rare cases would be a virtual keyboard, which is a pretty exotic and relatively rarely used kind of product. In my past answer, I explained the reason why it could be useful: Application focus getting and losing[^].
In most other cases, Topmost
is best avoided.
Also, it could be a very good idea to develop application using only one main form, not counting very small of modal forms of limited use. Instead of using other non-modal form, you implement similar behavior, where some panels or tab pages play the role of other forms. You can even develop docked UI like that in Visual Studio, but in very many cases, simple
TabControl
does a good job.
And finally, (sight), lets get to the multiple non-modal form. A main form, if activated,
must hide other forms under its bounding rectangle. And so should do any other form.
Not doing so would be a serious abuse.
At the same time, it's good to make sure that none of the windows not belonging to your application can appear between you forms in Z-order. This is done by having owner-owned relationship to bind all the non-modal form. It would be quite enough to make the main form an owner of all other non-modal forms. Please see:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.ownedforms(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.removeownedform(v=vs.110).aspx[
^].
Also, it would be good (at least in most typical cases), to allow only the main form (owner) to appear in the taskbar. This is how:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar(v=vs.110).aspx[
^].
—SA