protected override void OnTextChanged(EventArgs 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(IPAddressControlDirection.Forward, IPAddressControlSelection.All); }
private void OnFieldTextChanged(Object sender, TextChangedEventArgs e) { if (null != FieldChangedEvent) { FieldChangedEventArgs args = new FieldChangedEventArgs(); args.FieldIndex = e.FieldIndex; args.Text = e.Text; FieldChangedEvent(this, args); } OnTextChanged(EventArgs.Empty); }