The simplest way to do this is to first show (using ShowDialog
, which blocks i.e. waits until the form is closed before continuing to the next line of code) the login form. If the login is successful, you dispose the login form and then show your main form; if the login fails, you end the application.
If, however, you want your main form to be visible underneath the login form (a not unreasonable requirement), then you need to first show the main form, and then display the login form (modally) from a method in the main form. In WinForms this requires some kind of hack, since you couldn't show the login form from either the main form's constructor or its Load event (as the main form won't yet be visible when the login form appears).
WPF may handle this better now.