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); } }
protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); if (!Blank) { int val; if (!Int32.TryParse(Text, out val)) { Text = String.Empty; } else { if (val > RangeUpper) { Text = RangeUpper.ToString(CultureInfo.InvariantCulture); } else { Text = val.ToString(CultureInfo.InvariantCulture); } } } SelectionStart = this.TextLength; if (null != TextChangedEvent) { TextChangedEventArgs args = new TextChangedEventArgs(); args.FieldId = FieldId; args.Text = Text; TextChangedEvent(this, args); } if (Text.Length == MaxLength && Focused) { if (null != CedeFocusEvent) { CedeFocusEventArgs args = new CedeFocusEventArgs(); args.FieldId = FieldId; args.Direction = Direction.Forward; args.Selection = Selection.All; CedeFocusEvent(this, args); } } }