Dynamic Masks in radMaskedEditBox [Resolved]

2 posts, 0 answers
  1. Amilton
    Amilton avatar
    4 posts
    Member since:
    Mar 2014

    Posted 26 Jun 2015 Link to this post

    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

     

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 01 Jul 2015 Link to this post

    Hello Amilton,

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

    Regards,
    Hristo Merdjanov
    Telerik

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top