I added the option to return the address through the zip code in a Windows Form. I used a web service to get this data and added it in the following method:
private void ConsultaCEP()
{
var valor = txtCep.Text;
try
{
var ws = new WSCorreios.AtendeClienteClient();
var resposta = ws.consultaCEP(valor);
txtLogradouro.Text = resposta.end;
txtBairro.Text = resposta.bairro;
txtCidade.Text = resposta.cidade;
cbxUf.Text = resposta.uf;
}
catch (Exception ex)
{
lblAvisoCep.Visible = true;
lblAvisoCep.Text = "Erro ao efetuar busca";
txtCep.BackColor = Color.LemonChiffon;
txtCep.Clear();
txtCep.Focus();
}
}
And I called this method in the Leave event of the CEP textbox.
private void txtCep_Leave_1(object sender, EventArgs e)
{
ConsultaCEP();
}
However, when you enter an invalid ZIP code, the error message appears but the form hangs, and you can not change the cursor to any field other than ZIP code. How do I solve this problem?