Link to home
Start Free TrialLog in
Avatar of techsuppoprt
techsuppoprt

asked on

Closing initial Login Form from Program.cs

Morning Experts,

I'm having a bit of a brain fart. I think there is something small that I'm missing yet need help.

So.. pretty simple scenario:
Windows form app, Login window, which should be closed once user is authorized and the actual MDI application is presented.

 I modified the Program.cs file for the Login form to be displayed before the main application comes up ( code below ).
The authentication works but the Login form doesn't go away unless I close it separately. The only way it works right now If I authenticate and then close the form by hitting the Cancel button.

Any suggestions ?
Thank you in advance.
static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
 
            Login userLogin = new Login();
 
            while (!userLogin.UserIsAuthenticated && userLogin.LoginAttempts<3)
            {
                if (userLogin.ShowDialog() == DialogResult.Cancel)
                {
                    break;
                }
            }
 
            if (userLogin.UserIsAuthenticated)
            {
                Application.Run(new Main());
            }
 
            
        }
    }

Open in new window

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

I assume that login is a form ?

if (userLogin.UserIsAuthenticated)
            {
               Login.close();
                Application.Run(new Main());
            }
 
Avatar of techsuppoprt
techsuppoprt

ASKER

No,doesn't work.
That's the thing, it doesn't get to this "if (userLogin.UserIsAuthenticated)" block of code at all unless the form is closed or Canceled.

Any ideas ?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial