C# - How to close the login form(initial program form) after calling another form?

Asked

Viewed 1,984 times

2

I was able to do the entire database part of the login form, so that if the user enters login/password with data that are in the database, he can access.

Only when I open the other form, the login does not close and the most I could was hide it with this.Visible = false;

I want the second form to open and the login to close without the entire application crashing, since with this.close()/close() everything closed!

My login button code looks like this:

Obs: "access" is a boolean variable that I assign when creating the login/password part of the program’s database.

if (acessar == true)
        {
            MessageBox.Show("Logado com sucesso!");
            this.Visible = false;

            Form2 novaform = new Form2();
            novaform.ShowDialog();

        }

        else
        {
            MessageBox.Show("Erro ao logar");          
        }

2 answers

2

0

I did something kind of like this on my show.

//dentro da classe base do programa
public static bool reconect = true;
public static Usuario usuario = null;

//metodo Main()
while(reconect)
{
    reconect = false;
    Application.Run(new Login());
    // a variavel usuario é do tipo static, e é modificada quando o login é efetuado;
    if (usuario != null)
    {
        //caso seja feito o logoff, o usuario é setado em null e reconect para true.
        //se a TelaPrincipal ou Login for fechada ela automaticamente quebra o loop
        Application.Run(new TelaPrincipal());
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.