This is a migrated thread and some comments may be shown as answers.

Dynamic Masks in radMaskedEditBox [Resolved]

1 Answer 85 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Amilton
Top achievements
Rank 1
Amilton asked on 26 Jun 2015, 01:35 PM

Hello.

After a few tries, I came to a method that dynamically changes shades depending on the amount of characters MaskedEditBox:

public partial class RadForm6 : Telerik.WinControls.UI.RadForm
    {
        public RadForm6()
        {
            InitializeComponent();
            this.radMaskedEditBox1.TextChanged += radMaskedEditBox1_TextChanged;
            this.radMaskedEditBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
            this.radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Standard;
            this.radMaskedEditBox1.Mask = "000,000,000-0099";
            this.radMaskedEditBox1.PromptChar = ' ';
        }
 
        string initialValue = string.Empty;
        private void radMaskedEditBox1_TextChanged(object sender, EventArgs e)
        {
            if ((radMaskedEditBox1.Value + "").Length <= 11 && this.radMaskedEditBox1.Mask != "000,000,000-0099")
            {
                this.radMaskedEditBox1.TextChanged -= radMaskedEditBox1_TextChanged;
                initialValue = this.radMaskedEditBox1.Value + "";
                this.radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Standard;
                this.radMaskedEditBox1.Mask = "000,000,000-0099";
                this.radMaskedEditBox1.PromptChar = ' ';
                this.radMaskedEditBox1.Value = initialValue;
                this.radMaskedEditBox1.TextChanged += radMaskedEditBox1_TextChanged;
            }
            else if ((radMaskedEditBox1.Value + "").Length >= 12 && this.radMaskedEditBox1.Mask != "00,000,000/0000-00")
            {
                this.radMaskedEditBox1.TextChanged -= radMaskedEditBox1_TextChanged;
                initialValue = this.radMaskedEditBox1.Value + "";
                this.radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Standard;
                this.radMaskedEditBox1.Mask = "00,000,000/0000-00";
                //this.radMaskedEditBox1.PromptChar = ' ';
                this.radMaskedEditBox1.Value = initialValue;
                this.radMaskedEditBox1.TextChanged += radMaskedEditBox1_TextChanged;
            }
        }
 
    }

 

I hope it helps.

Regards,
Felipe

 

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 01 Jul 2015, 01:16 PM
Hello Amilton,

Thank you for sharing your solution. I am sure that our community will benefit from it.

Regards,
Hristo Merdjanov
Telerik

Tags
MaskedEditBox
Asked by
Amilton
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or