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

Re: Show loginwindow before MainWindow by Kevin

Kevin
Thu Nov 30 10:08:17 CST 2006

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.


"Stephan Zaubzer" <stephan.zaubzer@schendl.at> wrote in message
news:O90$YaJFHHA.4432@TK2MSFTNGP03.phx.gbl...
>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



Re: Show loginwindow before MainWindow by Kevin

Kevin
Thu Nov 30 21:49:37 CST 2006

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.


"Ciaran O''Donnell" <CiaranODonnell@discussions.microsoft.com> wrote in
message news:006E64C2-425F-4847-B279-A8DEE91EAA40@microsoft.com...
> Its best to put it in Main and not call application run on login failure.
> In
> OnLoad, you can sometimes see the main form flash up and disappear again.
> Dont bother wating time loading it.
>
> --
>
> Ciaran O''Donnell
> http://wannabedeveloper.space.live.com
>
>
> "Kevin Spencer" wrote:
>
>> 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.
>>
>>
>> "Stephan Zaubzer" <stephan.zaubzer@schendl.at> wrote in message
>> news:O90$YaJFHHA.4432@TK2MSFTNGP03.phx.gbl...
>> >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
>>
>>
>>