If you want to implement navigation, ask about implementation of navigation, not about closing and showing forms.
Probably the best way to implement frame-by-frame kind of navigation and many different kinds of navigation is using only one form. Simply show different content on the form on each step. In simplest case, you can have several instanced of
Panel
docked using
DockStyle.Fill
(anyway, everything if Forms should be docked, to ensure stable and well maintainable layout), showing only one at a time. Navigation can hide current panel, showing another one. Then navigation controls themselves should of course be always visible.
Please see:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle%28v=vs.110%29.aspx[
^].
To come back to several forms, the problems are: if you close a form, you cannot show it again; and if you close main form, it will exit the application. Therefore, if you use this for navigation (again, I don't recommend it), you should hide forms instead of closing. You don't need [x] non-client control box at all, but to prevent closing a form, you can replace the action with hiding in the following way: override the event
FormClosing
or override the virtual method
Form.OnFormClosing
and then cancel closing. It's done by assigning of the event arguments' property
Cancel
to true, but only if
CloseReason
equals to
CloseReason.UserClosing
, to allow closing by other reasons. Hide the form instead.
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.closereason%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.closereason%28v=vs.110%29.aspx[
^].
Knowing this technique is useful in many cases, but, again, using multiple forms for navigation is not what I recommend. Better use a single form with changed visibility of content. Or, alternatively/additionally, re-populate the controls in different ways for different frames on the fly.
—SA