Beispiel #1
0
        protected override void OnTextChanged(TextChangedEventArgs e)
        {
            base.OnTextChanged(e);

            string text = Text.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty);

            string     mask = Mask;
            ValueTypes vt   = ValueType;

            if (0 != mask.Length)
            {
                if (0 < Text.Length)
                {
                    if (vt.Equals(ValueTypes.Integer))
                    {
                        Text      = String.Format("{" + mask + "}", Int32.Parse(text));
                        e.Handled = true;
                    }
                    else
                    {
                        Text      = String.Format("{" + mask + "}", Double.Parse(text));
                        e.Handled = true;
                    }
                }
                else
                {
                    Text      = "";
                    e.Handled = true;
                }
            }
        }
Beispiel #2
0
        private bool IsSymbolValid(string mask, string str, ValueTypes typ)
        {
            switch (typ)
            {
            case ValueTypes.Text:
                return(true);

            case ValueTypes.Integer:
                if (str == NumberFormatInfo.CurrentInfo.NegativeSign)
                {
                    return(true);
                }
                break;

            case ValueTypes.Double:
                if (str == NumberFormatInfo.CurrentInfo.NumberDecimalSeparator ||
                    str == NumberFormatInfo.CurrentInfo.NegativeSign)
                {
                    return(true);
                }
                break;
            }

            if (typ.Equals(ValueTypes.Integer) || typ.Equals(ValueTypes.Double))
            {
                foreach (char ch in str)
                {
                    if (!Char.IsDigit(ch))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }