Cancel button of a Login C # form

1

I have a problem with this event code click on the cancel button of a login form.

private void btnCancelar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(@"Esta seguro que desea salir del sistema?", @"Atención",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
            else
            {
                txtUsuario.Focus();
            }
        }

Pressing the cancel button opens a warning message of whether or not I am sure of leaving the system, by pressing "no" it would be closing the same, I would appreciate your help.

    
asked by Daniel Bejar 12.10.2018 в 20:03
source

1 answer

2

If your button has the property DialogResult = Cancel (For example) the form interprets it as a if you send a DialogResult response.

but to make it work as you want, add this line of code:

private void btnCancelar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(@"Esta seguro que desea salir del sistema?", @"Atención",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
            else
            {
                this.DialogResult = DialogResult.None;
                txtUsuario.Focus();
            }
        }

Greetings

    
answered by 12.10.2018 / 21:26
source