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

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

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

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

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

            if (this.TextLength == this.MaxLength && this.Focused && this.SelectionStart == this.TextLength)
                this.SendCedeFocusEvent(IPAddressControlDirection.Forward, IPAddressControlSelection.All);
        }
Example #2
0
        private void OnFieldTextChanged(Object sender, TextChangedEventArgs e)
        {
            if (null != this.FieldChangedEvent)
            {
                FieldChangedEventArgs args = new FieldChangedEventArgs {FieldIndex = e.FieldIndex, Text = e.Text};
                this.FieldChangedEvent(this, args);
            }

            this.OnTextChanged(EventArgs.Empty);
        }