How to apply 2 mascara in the same textbox windows form c #

2

I have 2 checkbox of person and company, and only a textbox .

I want to select in% with% of individual, I want to apply the mask to CPF, or when selecting the legal entity, it applies the mask to CNPJ in checkbox .

I do not know how to apply the mask according to what I selected.

    
asked by anonymous 15.03.2018 / 18:29

1 answer

5

On a weekly basis, it would be correct to use radio button instead of checkboxes , since the user can only select one of the options.

Either way, the implementation is exactly the same:

In the checked event of the element that defines the type of person (the checkbox ) you should do something like this
private void rbPessoaFisica_CheckedChanged(object sender, EventArgs e)
{
    txtDocumento.Mask = rbPessoaFisica.Checked ? @"000\.000\.000\-00" : @"00\.000\.000\/0000\-00";
}

See working below

    
15.03.2018 / 18:42