protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            if (!Blank)
            {
                try
                {
                    int value = Int32.Parse(Text, CultureInfo.InvariantCulture);

                    if (value > RangeUpper)
                    {
                        base.Text      = RangeUpper.ToString(CultureInfo.InvariantCulture);
                        SelectionStart = 0;
                    }
                    else if ((TextLength == MaxLength) && (value < RangeLower))
                    {
                        base.Text      = RangeLower.ToString(CultureInfo.InvariantCulture);
                        SelectionStart = 0;
                    }
                    else
                    {
                        int originalLength    = TextLength;
                        int newSelectionStart = SelectionStart;

                        base.Text = value.ToString(CultureInfo.InvariantCulture);

                        if (TextLength < originalLength)
                        {
                            newSelectionStart -= (originalLength - TextLength);
                            SelectionStart     = Math.Max(0, newSelectionStart);
                        }
                    }
                }
                catch (ArgumentNullException)
                {
                    Text = String.Empty;
                }
                catch (FormatException)
                {
                    Text = String.Empty;
                }
                catch (OverflowException)
                {
                    Text = String.Empty;
                }
            }

            if (TextChangedEvent != null)
            {
                TextChangedEvent(FieldIndex, Text);
            }

            if (TextLength == MaxLength && Focused && SelectionStart == TextLength)
            {
                SendCedeFocusEvent(Direction.Forward, Selection.All);
            }
        }
Exemplo n.º 2
0
        protected override void OnTextChanged(EventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            base.OnTextChanged(e);

            if (!Blank)
            {
                int value;
                if (!Int32.TryParse(Text, out value))
                {
                    base.Text = String.Empty;
                }
                else
                {
                    if (value > RangeUpper)
                    {
                        base.Text      = RangeUpper.ToString(CultureInfo.InvariantCulture);
                        SelectionStart = 0;
                    }
                    else if ((TextLength == MaxLength) && (value < RangeLower))
                    {
                        base.Text      = RangeLower.ToString(CultureInfo.InvariantCulture);
                        SelectionStart = 0;
                    }
                    else
                    {
                        int originalLength    = TextLength;
                        int newSelectionStart = SelectionStart;

                        base.Text = value.ToString(CultureInfo.InvariantCulture);

                        if (TextLength < originalLength)
                        {
                            newSelectionStart -= (originalLength - TextLength);
                            SelectionStart     = Math.Max(0, newSelectionStart);
                        }
                    }
                }
            }

            if (null != TextChangedEvent)
            {
                TextChangedEventArgs args = new TextChangedEventArgs();
                args.FieldIndex = FieldIndex;
                args.Text       = Text;
                TextChangedEvent(this, args);
            }

            if (TextLength == MaxLength && Focused && SelectionStart == TextLength)
            {
                SendCedeFocusEvent(Direction.Forward, Selection.All);
            }
        }
Exemplo n.º 3
0
        protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
        {
            base.OnValidating(e);

            if (!Blank)
            {
                if (Value < RangeLower)
                {
                    Text = RangeLower.ToString(CultureInfo.InvariantCulture);
                }
            }
        }