How can I get the current number that's in a numericUpDown control (on the screen) when the user is editing it via the keyboard?

StackOverflow https://stackoverflow.com/questions/7855942

  •  10-02-2021
  •  | 
  •  

Question

I have a numericUpDown picker that's set to a range of acceptable years, defaulting to the current year.

The user can edit the number in the box with the keyboard: say if the number in there is 2011 to begin with, they can press backspace and the number in the box on screen will be 201. However, as far as I know, the value property of the control will never read a number below the minimum I set (1900 in this case).

I need a way to get the number currently in the box on the screen regardless of whether it is in my acceptable range or not. Anyone know how to do this?

Thanks!

Was it helpful?

Solution

You can use the NumericUpDown.Text property to get the current text, then parse to int. It may not look like the property exists, but it's there.

The Text has no affect on the appearance of the NumericUpDown control; therefore, it is hidden in the designer and from IntelliSense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top