Close Form Open a new Form c #

1

Good evening, I would like you to help me.

I am new to c # and I would like you to help me. I am making a login but when I enter I want to enter another form and close the form that I logged in.

This is the current code:

private void btnIngresar_Click(object sender, EventArgs e)
{
    try
    {
        if (txtUsuario.Text.Trim() == "")
        {
            MessageBox.Show("Ingrese el Usuario", "Aviso del Sistema");
        }
        else if (txtpassword.Text.Trim() == "")
        {
            MessageBox.Show("Ingrese su Password", "Aviso del Sistema");
        }
        else
        {
            obj.Alu_Usuario = txtUsuario.Text;
            obj.Alu_llave = txtpassword.Text;
            obj.Opc = 1;

            string resP = Cls_N_Alumno.ConsultarLogin(obj).Rows[0][0].ToString();

            if (resP == "1")
            {
                txtpassword.Text = "";
                txtUsuario.Text = "";
                MessageBox.Show("Usuario Correctos", "Aviso del Sistema");
                FrmMenu frm = new FrmMenu();
                frm.Show();
                this.Close();



            }
            else
            {
                MessageBox.Show("Error Login", "Aviso del Sistema");
            }

        }
    }
    
asked by PieroDev 17.03.2017 в 05:35
source

3 answers

4

You should not have to close any form when you perform a login, because it is assumed that this authentication form is implemented before assigning the Application.Run()

If you define the login form within the Main() that is in Program.cs you can authenticate and then indicate which is the main form

This is explained in the article

Login - Using Password with Hash

[Winform] Perform tasks before initializing application

analyzes how the login dialog is shown and then if the authentication is correct the main form is opened, but without having to hide any form

    
answered by 17.03.2017 в 12:34
0

When the login is correct, you can close the current one and open another one as follows:

Hide(); //Oculta el formulario actual
menu formMenu = new menu(); //creamos instancia del Formulario Menú
formMenu.Show(); //abrimos el nuevo Formulario        
    
answered by 17.03.2017 в 10:10
0

In this way you can minimize the current form and go to another, you can adapt this example to your problem.

private void btn_VolverAlRegistro_Click(object sender, EventArgs e)
        {
            Empleados frm = new Empleados();

            frm.Show();
            this.Hide();
        }

Take into account: Employees is the name of the form I want to go to.

I hope somehow it works for future visits to this question.

    
answered by 23.02.2018 в 15:10