1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Windows.Forms;
- namespace PaintDotNet
- {
- /// <summary>
- /// This class implements some common things on top of the regular NumericUpDown class.
- /// </summary>
- 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);
- }
- }
- }
|