PdnNumericUpDown.cs 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Windows.Forms;
  3. namespace PaintDotNet
  4. {
  5. /// <summary>
  6. /// This class implements some common things on top of the regular NumericUpDown class.
  7. /// </summary>
  8. public class PdnNumericUpDown
  9. : NumericUpDown
  10. {
  11. public PdnNumericUpDown()
  12. {
  13. TextAlign = HorizontalAlignment.Right;
  14. }
  15. protected override void OnEnter(EventArgs e)
  16. {
  17. Select(0, Text.Length);
  18. base.OnEnter(e);
  19. }
  20. protected override void OnLeave(EventArgs e)
  21. {
  22. if (Value < Minimum)
  23. {
  24. Value = Minimum;
  25. }
  26. else if (Value > Maximum)
  27. {
  28. Value = Maximum;
  29. }
  30. decimal parsedValue;
  31. if (decimal.TryParse(Text, out parsedValue))
  32. {
  33. Value = parsedValue;
  34. }
  35. base.OnLeave(e);
  36. }
  37. }
  38. }