Do not use many forms, it's the worst. Do not use MDI, this is highly discourages (even by Microsoft) and very inconvenient to everyone. Here is the simplest thing to use: Tabbed interface. Use the control
System.Windows.Forms.TabControl
. You can add any number of tabs to it, with Designer or during run-time. What you had in the content of each form put is a separate tab.
[EDIT1]
If you need a log in first, do the following. Create one more form for log in. In the very beginning show it in a modal form calling
System.Windows.Forms.Form.ShowDialog
. After successful log in, this form will be closed and never needed again. In case of failure to log in, exit application after the modal dialog is returned with
System.Windows.Forms.Application.Exit
. This will be the optimal solution.
[END EDIT1]
[EDIT2]
Consider again: you have two forms: 1) Log in form, 2) Multi-tab form.
When you run your entry point, run
System.Windows.Forms.Application
form with Multi-tab form,
not with login form. It will make your Multi-tab form the main one. Variant #1: in your entry-point method, call
System.Windows.Forms.Form.ShowDialog
with the log-in form before
Application.Run
. If the log in is not successful, just exit, so
Application.Run
will be never called. Variant #2: Handle the event
Shown
of the main form to call
System.Windows.Forms.Form.ShowDialog
with the log-in form. If log in is successful, just continue; if not — call
System.Windows.Forms.Application.Exit
right withing the handler (it works). Quite simple.
[END EDIT2]
[EDIT3]
See my solution of collaboration between forms and the discussions:
How to copy all the items between listboxes in two forms[
^].
[END EDIT3]
This is easy.
—SA