Search code examples
c#winformstelerik

RadMaskedTextBox How to showing last 4 characters?


I want to create a mask in a textbox (RadMaskedTextBox) that is showing the last 4 characters. But what I see is the first 4 characters. What do I wrong?

  • DataBindings is set to a field of a string number of 9 character. (SQL Server/LINQ-to-SQL) in property Value.
  • Mask is set to "*****0000".
  • MaskType is set to Standard.

enter image description here


Solution

  • You can achieve similar behavior with any textbox (or maskedTextBox with empty mask) using the _Leave event.

        private void maskedTextBox1_Leave(object sender, EventArgs e)
        {
            var text = maskedTextBox1.Text;
            maskedTextBox1.Text = new string('*', text.Length - 4) + text.Substring(text.Length - 4);
        }