Re: Can recall frmLogIn ?
What do you mean, 'recall'? Are you saying you want to display the login form again?
Re: Can recall frmLogIn ?
Quote:
Originally Posted by
Arjay
What do you mean, 'recall'? Are you saying you want to display the login form again?
Yes, I want re_show frmLogIn when frmLogIn hide because the frmLogIn call to Application.Run(new frmLogIn()). can you recall frmLogIn ?
Re: Can recall frmLogIn ?
Quote:
Originally Posted by
dongtrien
Yes, I want re_show frmLogIn when frmLogIn hide because the frmLogIn call to Application.Run(new frmLogIn()). can you recall frmLogIn ?
Rather than hide/show frmLogIn, start the app with frmMain.
Code:
Application.Run(new frmMain());
Set frmMain to be initially hidden and then call frmLogIn to authenticate. If the user is authenticated, show the main form (or exit the app as appropriate).
If you need to call frmLogIn later, simply display is as you would when you display any modal form.
Re: Can recall frmLogIn ?
I do not understand you to said, from my example above you how to rewrite recall frmLogin ?
Re: Can recall frmLogIn ?
Quote:
Originally Posted by
dongtrien
I do not understand you to said, from my example above you how to rewrite recall frmLogin ?
In order to understand what I'm talking about, you need to understand how Application.Run and the form that is passed to it works. With a .net app, the form you pass to Application.Run controls the lifetime of the application. When you close this form, the application (process) shuts down.
So that is why you can't call Application.Run twice (once with login and again with main).
What you need to do is start the app with a form that always exists (although it may be hidden sometimes).
You can do this two ways. The first way is to pass frmLogin to the app, and when the user logs in, hide frmLogin and create and display the frmMain as a modeless form. When you need to show the frmLogin, hide frmMain and show frmLogin.
The other way to do this is to do this is to start the app with frmMain but initially hidden, and then display frmLogin as a modal form. If the user can't authenticate, you close frmMain (which causes the app to exit). If the user authenticates, you close frmLogin and show frmMain. If you need to show frmLogin you create another instance of it and display it as a modal form.
Since most of the functionality of your app isn't just logging on (I presume), I prefer the second approach because there are some subtleties when working with modeless forms that you can avoid by going with the second approach.