HELP ME If Condition in a Maskedtextbox

Asked

Viewed 44 times

0

Guys, I know this site is very famous because the community is SUPER charitable and kind. Help me with this: I can’t get a Messagebox to show when I leave my Maskedtextbox blank. I formatted it to stay in the standard CPF 123.456.789-00 I’m making a registration form. I can do for normal Textbox, but for Maskedttextbox it doesn’t work. The code is like this:

if(txtNome.Text == "")
            {
                MessageBox.Show("Preencha o campo Nome!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if(txtCpf.Text == "") // <- Essa é a MaskedTextBox
            {
                MessageBox.Show("Preencha o campo CPF!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
  • the secret is how you ask the question... everything you typed there could be just "maskedtextbox is Empty", and then: https://stackoverflow.com/a/17757922/4713574

  • Thank you so much, Rovann. You saved my night, man! God bless you :D

1 answer

1

There are several ways to check whether or not a Maskedtextbox is empty. Follow the code below that checks without error.

            if (maskedTextBox1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("Preencha o campo CPF!", "Falta de informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

Browser other questions tagged

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