The NumericUpDown administration is generally acclimated get numeric information sources and consequently confines client for giving invalid non-numeric qualities.The Numeric UpDown management looks like a TextBox management, but there ar arrow buttons on its right or left side that is accustomed increment or decrement the value of the management.

The numeric value of the Numeric UpDown control can be accessed or retrieved using the Value property which is of type decimal. The following are some of the properties of the Numeric UpDown control.

Property Description
DecimalPlaces Indicates the number of decimal places to display.
Hexadecimal Indicates whether the NumericUpDown control should display its value in hexadecimal.
Increment Indicates the quantity which will be incremented or decremented to the present price once the arrow buttons area unit ironed.
InterceptArrowKeys If set to true, you can use the arrow keys in your keyboard to increment or decrement the value.
Maximum Indicates the maximum value that the NumericUpDown control can contain.
Minimum Indicates the minimum value that the NumericUpDown control can contain.
ThousandsSeperator Indicates whether the value will be displayed with the thousands separator. (example: 1,000)
UpDownAlign Indicates wherever the arrow buttons area unit positioned. Set to Right to place the buttons to the proper aspect and Leftto place them to the left aspect.
Value The present estimation of the NumericUpDown control.

Figure 1 – NumericUpDown Control Properties

The default and most useful event of the NumericUpDown control are the ValueChanged event which executes whenever the Value property of the NumericUpDown control is changed.

Let’s create an example program which uses the NumericUpDown control. Create a new Windows Forms Application and name it NumericUpDown Demo. Add two labels, and two NumericUpDown controls. Change the text of the labels to “Price” and “Quantity” respectively. Include a Button control and change its subtitle to “Compute”. Adjust the controls as appeared in Figure 2.

numericupdown
numericupdown

Change the properties of the following control:

Control Property Value
button1 Name buttonCalculate
numericUpDown1 Name numericUpDownPrice
Decimal 2
Increment 0.50
Maximum 10000
numericUpDown2 Name numericUpDownQuantity
Maximum 100

Figure 3

The numericUpDownPrice control’s Decimal property was set to a pair of therefore it will have a exactness of two decimal places. It’s Incrementproperty is prepared to zero.50 thusly every augmentation or decrements includes or subtracts the value by zero.50. The Maximum property indicated was ten thousand, therefore the worth is restricted to the present quantity. The numericUpDownQuantity controls most price was set to a hundred therefore you’ll solely order a most of a hundred things.

Double-click the button and to add an event handler to its Click event. Add the following code:

private void buttonCalculate_Click(object sender, EventArgs e)
{
    decimal price = numericUpDownPrice.Value;
    int quantity = (int)numericUpDownQuantity.Value;
    decimal total;
 
    total = price * quantity;
 
    MessageBox.Show(String.Format("The total price is {0:C}", total));
}

Run the program. Have a go at augmenting or decrementing the estimations of the numericUpDownPrice and you will see that it increases at 0.50 interim.

numericupdown
numericupdown

Click the Calculate button and also the program can confirm the full worth by multiplying the Values of both NumericUpDown control.

numericupdown
numericupdown