Copy and paste string without mask

Asked

Viewed 86 times

1

I’m using a MaskedTextBox containing a mask of CNPJ (00.000.000/0000-00).

But I wish that when I copied this string it would come to the clipboard without the mask, to remove the mask I’m doing this:

maskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
//área de transferência = maskedTextBox1.Text; (???)

However I do not know which event and to whom I should assign the value without formatting, so copy (CTRL + C) the no mask string for the clipboard.

  • 2

    You can manipulate with the KeyDown over the control of MaskedTextBox.

  • @Cypherpotato hmm true, but to whom I will assign the value without mask?

  • 1

    System.Windows.Forms.Clipboard.SetText(maskedTextBox1.Text) :)

1 answer

3


  • I even removed my answer because that’s the correct answer. It’s simple and more efficient than intercepting keyboard events.

Browser other questions tagged

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