title: C# - How to Change Dynamically the Mask of the MaskedTextBox?
body: <p>Here's the problem:
  I'm using a MaskedTextBox for phones masks. But, the Mask must accept two kinds of mask, like, the default mask is like this (00) 0000-0000, but sometimes the mask need to have one more slot, like this (00) 0000-00000.
  This process must be dynamic. If the user type more than 10 chars, the MaskedTextBox will change his own mask.
  Some time ago, I made it using VB.Net, but now, I need to do this using C#.</p>
  
  <p>Here's just a example using VB.NET that I made some time ago.</p>
  
  <pre><code>Private Sub MaskedTextValidacao_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Validating
      Me.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
  
      If Me.Text.Contains(" ") Or Me.Text.EndsWith(" ") Or Me.Text.StartsWith(" ") Then
          Me.Text.Replace(" ", "")
      End If
  
      If Me.Text.Count.Equals(10) Or Me.MaskCompleted.Equals(True) Then
          Me.BackColor = Color.LightGreen
          Me.Text = Me.Text.TrimEnd
      ElseIf Me.Text = "" Then
          Me.BackColor = Color.White
      Else
          Me.BackColor = Color.LightCyan
      End If
  
  End Sub
  </code></pre>
  
  <p>Now, I'm trying to make something better and using C#.</p>
  
  <p>Can someone help me? I mean, just give me a light, because I'm stuck!</p>