Show loginwindow before MainWindow

S

Stephan Zaubzer

I have an application which uses a main window. But before showing the
Main Window (which is best done by Application.Run(new MainWindow();) I
need to show a Login Window. When the login fails, the application
should terminate but when the login is successful the loginwindow should
be destroyed and the main application window should be presented to the
user.

What is the best way to do it?
-Can I call loginwindow.Showdialog() before calling Application.Run(new
MainWindow()
-Or should I create and show the loginwindow, then call
Application.Run() without a form as parameter and within the loginwindow
either call application.exit() or instantiate the MainWindow and upon
closing the mainwindow call application.exit().
Regards
Stephan
 
K

Kevin Spencer

The easiest way is to call the loginWindow.ShowDialog() method in the OnLoad
method of your form. The form will not appear until the OnLoad method
completes, and it can check the DialogResult of the method execution to
determine whether or not to close.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

Parabola is a mate of plane.
 
K

Kevin Spencer

That is true. That is why I said "the easiest way." It is not "the best
way." The best way is a bit more complicated, and involves creating an
inherited class derived from System.Windows.Forms.ApplicationContext. You
call the Application.Run method, passing the inherited ApplicationContext
class instance to it. This enables you to have complete control over as many
forms running in succession as you wish.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

Parabola is a mate of plane.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top