In addition to what Una advised I will advice to
1) Make the new form owned by the main form (main form is the one use in
Application.Run
). To do it, see
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx[
^]; doing so is important for application integrity; when all forms are owned by the main one, the activation of any form looks like activation of the application, no other application's form cannot be put in Z-order between the forms of your application; which is really good.
2) I would set the property
ShowInTaskbar
to
false
for all forms except main; the reason is the same as explained above: the main form will represent the whole application in the task bar.
3) Create a new form in a lazy manner: when the variable is
null
, create a form, otherwise show already created form.
4) You won't be able to work with non-main form when a user close it. To solve this problem, hide the form on attempt to close it; to do that, handle the event
FormClosing
; see the code sample here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx[
^]; in the code, write
form2.Hide()
before
e.Cancel = true
.
5) Try to avoid more than one form per application, at least limit the number of non-main forms by a very few (and perhaps few modal forms); you can leave with just one main form using
TabControl
and other similar means to show and hide groups of controls, all within one form.
—SA