The numeric up down widget consists of a text box and a spinner with up and down buttons. The text box shows and also can be used to edit the current numeric value and accepts only digits and the decimal separator. The current value is stored in the Value property. When it changes the ValueChanged event is fired. The range is determined by the Minimum and Maximum properties. The Step property defines how much to increase/decrease the current value when the user clicks on the increase/decrease spinner button or presses the up/down key from the keyboard while the numeric up down text box is focused. You can also set the number of decimal places the numeric up down will show through the DecimalPlaces property.
The following example demonstrates how to create a numeric up down widget and subscribe for its ValueChanged event:
Numeric Up Down Example |
Copy Code
|
---|---|
NNumericUpDown numericUpDown = new NNumericUpDown(); numericUpDown.Minimum = 0; numericUpDown.Maximum = 100; numericUpDown.Value = 40; numericUpDown.ValueChanged += new Function<NValueChangeEventArgs>(OnNumericUpDownValueChanged); private void OnNumericUpDownValueChanged(NValueChangeEventArgs arg1) { // Get the new value double value = (double)arg1.NewValue; // Get the numeric up down, whose value has changed NNumericUpDown numericUpDown = (NNumericUpDown)arg1.CurrentTargetNode; } |