1

So I'm attempting to build a login form inside of my container form in which case my container form shouldn't actually open until my login form has completed.

Inside of my Main() I have the following:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Authentication auth = new Authentication();
        if (auth.ActiveDirectoryAuthentication())
        {
            Application.Run(new ContainerForm());
        }
        else
        {
            //Do nothing as the user has failed. 
        }
    }

Now inside my LoginFailed() method which is intended to handle showing the LoginForm is the following:

private void FailedAuthentication()
        {
            //TODO: Show login form and start at AD manual authentication. 
            LoginForm login = new LoginForm();
            login.Show();

        }

Now for obvious reasons this will show the form for a second before the application closes. I need to be able to show the login form before the container form can be viewed and then once the login form closes (which is handled in the click) How can I continue my code to show the Application.Run(new ContainerForm()); after the login for closes?

Cody J. Mathis
  • 652
  • 1
  • 9
  • 25
  • So whats the question? – BugFinder Jul 27 '16 at 14:14
  • **I want to be able to continue my code to show the Application.Run(new ContainerForm());** --> **_How can I_ continue my code to show the Application.Run(new ContainerForm());** – Cody J. Mathis Jul 27 '16 at 14:15
  • Added the 4 words to the post as well. – Cody J. Mathis Jul 27 '16 at 14:17
  • Okay, so did I understand correctly. When the user opens the application they only see a login form. They input the data and try to log in. If the login succeeds, the login form closes and only then the main form opens. Is that correct? – Timo Salomäki Jul 27 '16 at 14:19
  • 1
    Use an `ApplicationContext`, check [the MSDN example](https://msdn.microsoft.com/en-us/library/ms157901(v=vs.110).aspx#Anchor_3), it shows exactly what you want. – Maarten Jul 27 '16 at 14:21
  • Instantiate a ContainerForm instance ready for use and simply swap to it when your login form closes, so that the application doesn't close after your login form closes. So, `ContainerForm containerForm = new ContainerForm();`. Then, do `if (!auth.ActiveDirectoryAuthentication()) { //open login form }`. After that simply open your ContainerForm. You'll have to make it hinge on successful login, or a default true value (when using active directory login). – ManoDestra Jul 27 '16 at 14:22

0 Answers0