When I close the Form executes the Leave event

Asked

Viewed 126 times

0

In my application I created an event Leave in the maskCnpj, when I close my form I have to click 3 times in the window messageBox there’s some way to settle this?

if (maskCnpj.Text != "  .   .   /    -")
{
    lblAjuda2.Text = "";
    ValidaDocEmailModel ObjValidaDoc = new ValidaDocEmailModel();

    cnpj = new ValidaDocEmailModel().DuplicidadeCNPJ(maskCnpj.Text);

    if (ObjValidaDoc.ValidaCNPJ(maskCnpj.Text))
    {
         if (cnpj)
         {
            lblAjuda2.Text = "Este CNPJ já existe !!!!!!!";
            CarregarCamposCnpjExixtente();
            DesabilitarCampos();

         }
    }
    else
    {
        MessageBox.Show("este cnpj já é inválido ");
        lblAjuda2.Text = "O CNPJ é Inválido, por favor digite um CNPJ válido";
        modo = "Salvar";
        maskCnpj.Focus();
    }
}
else
{
    MessageBox.Show("O CNPJ não pode ser Vazio !!!!!!");
    maskCnpj.Focus();
}

1 answer

0

change your if condition to only maskCnpj.Text != "" , there is no need to check the characters if you will make the mask later, and it seems that the function of Focus() is persisting the message, until a moment you can click to close the form faster than the function is executed.

Browser other questions tagged

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