-
June 28th, 2014, 11:21 PM
#1
Can recall frmLogIn ?
suppose, I've program includes 2 frmLogIn and frmMain, the syntax recall frmLogIn in frmMain how ? you see my code below:
in Program.cs file
Code:
...
Application.Run(new frmLogIn());
in frmLogIn.cs file
Code:
private void CmdLogIn_Click(object sender, EventArgs e)
{
...
this.Hide(); // of frmLogIn
this.DialogResult = DialogResult.OK; // of frmLogIn
frmMain _frmMain = new frmMain();
_frmMain.Activate();
_frmMain.Show();
}
in frmMain.cs file
Code:
/* // Don't called frmLogIn in this way
// If called frmLogIn in this way will be 2 frmLogIn in memory
frmLogIn _frmLogIn = new frmLogIn();
_frmLogIn.Activate();
_frmLogIn.Show();
*/
// I want recall frmLogIn in here, the syntax recall frmLogIn how ?
-
June 29th, 2014, 12:13 PM
#2
Re: Can recall frmLogIn ?
What do you mean, 'recall'? Are you saying you want to display the login form again?
-
July 1st, 2014, 05:07 AM
#3
Re: Can recall frmLogIn ?
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 ?
-
July 1st, 2014, 08:51 AM
#4
Re: Can recall frmLogIn ?
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.
-
July 2nd, 2014, 12:54 AM
#5
Re: Can recall frmLogIn ?
I do not understand you to said, from my example above you how to rewrite recall frmLogin ?
-
July 2nd, 2014, 09:16 AM
#6
Re: Can recall frmLogIn ?
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.
Last edited by Arjay; July 2nd, 2014 at 09:33 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|