Peter,
You could always call the static Exit method on the Application class.
This should send a shutdown message to your app, which would then close.
However, to get the kind of behavior that you want, I think that you
need to go through a loop, like so:
// In main section.
// Continue?
bool cont = true;
while (cont)
{
// Create login form and show it.
LoginForm loginForm = new LoginForm();
// Show in a message loop.
Application.Run(loginForm);
// Check a property to see if the form actually was logged into
correctly, or not cancelled.
// Make sure to name this property something else.
cont = loginForm.ShouldContinue;
// If continuing, then show the main form.
if (cont)
{
// Show the MDI form.
ClientForm clientForm = new ClientForm();
// Show.
Application.Run(clientForm);
}
}
This should give you the behavior that you want, and calling
Application.Exit anywhere from within your main client code should cause you
to exit (although I don't think that is a good idea, personally).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"pnp" <pnp.@.softlab.ntua.gr> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I'm working on a win app that uses a logon form to verify the user that
logs in the program and then hides the first form and displays an MDI form
where the user does his work. The app is STA.
The problem is that I wan't to be able to close the app from wherever in
my app (no matter how deep in the code) and make sure that all the
resources are being freed after exiting the app. Any ideas?
Is there a way to re-open the app programmaticaly after it has been closed
so that another user can login?
Thanks in advance,
Peter.