Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My startup form is loading. I need to close the loading form and open login form. I use the code
this.Dispose();
this.Close();
frmLogin objS = new frmLogin();
objS.ShowDialog();

When i use this code my application close the loading and also login finally my application exits. I dont know how to set property when last form closes.

Can any1 help in this.

( Close loading and Open login form )
Posted
Comments
WarLock007 13-Mar-14 2:35am    
please explain the scenario with some what more details so that it will be possible to give the desired solution. (i.e. how you want to display your "login form" either automatically after specified time or else after click on "loading form" or any control placed on "loading form")
Sergey Alexandrovich Kryukov 13-Mar-14 2:42am    
Do you mean System.Windows.Forms.Form, or something else?
—SA

1 solution

In the main form Load() event you have to invoke the Login form and to manage the result of the login: to let the main form to show or not (based on the user input).
Here is an example:

C#
private void FileManagerForm_Load(object sender, EventArgs e)
        {
            //
            // Login into the application
            //
            this.Hide(); //Hide the main form, so login form will be shown first!
            if (!DoLogin())
            {
                this.Close();
                return;
            }
//
// Show the main form!
//
this.Show();
//...
}

 private bool DoLogin()
        {
            Logout();
            //
            // Try to login
            //
            Des3 des3 = new Des3();
            LoginForm form = new LoginForm()
                                 {
                                     UserName = Settings.Default.UserName,
                                     Password = String.IsNullOrEmpty(Settings.Default.Password) ? string.Empty : des3.Decrypt(Settings.Default.Password),
                                     CheckCredentials = Settings.Default.RememberMe,
                                     LoginFormParent = this
                                 };
            //
            if (DialogResult.OK != form.ShowDialog() || this.SessionGuid == null)
                return false;
...
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900