using System; using System.Windows.Forms; namespace PaintDotNet { /// /// This class implements some common things on top of the regular NumericUpDown class. /// public class PdnNumericUpDown : NumericUpDown { public PdnNumericUpDown() { TextAlign = HorizontalAlignment.Right; } protected override void OnEnter(EventArgs e) { Select(0, Text.Length); base.OnEnter(e); } protected override void OnLeave(EventArgs e) { if (Value < Minimum) { Value = Minimum; } else if (Value > Maximum) { Value = Maximum; } decimal parsedValue; if (decimal.TryParse(Text, out parsedValue)) { Value = parsedValue; } base.OnLeave(e); } } }