Share via


How to: Set and Return Numeric Values with the Windows Forms NumericUpDown Control

The numeric value of the Windows Forms NumericUpDown control is determined by its Value property. You can write conditional tests for the control's value just as with any other property. Once the Value property is set, you can adjust it directly by writing code to perform operations on it, or you can call the UpButton and DownButton methods.

To set the numeric value

  1. Assign a value to the Value property in code or in the Properties window.

    NumericUpDown1.Value = 55
    
    numericUpDown1.Value = 55;
    
    numericUpDown1.set_Value(new Decimal(55));
    
    numericUpDown1->Value = 55;
    

    -or-

  2. Call the UpButton or DownButton method to increase or decrease the value by the amount specified in the Increment property.

    NumericUpDown1.UpButton()
    
    numericUpDown1.UpButton();
    
    numericUpDown1.UpButton();
    
    numericUpDown1->UpButton();
    

To return the numeric value

  • Access the Value property in code.

    If NumericUpDown1.Value >= 65 Then
       MessageBox.Show("Age is: " & NumericUpDown1.Value.ToString)
    Else
       MessageBox.Show("The customer is ineligible for a senior citizen discount.")
    End If
    
    if(numericUpDown1.Value >= 65)
    {
       MessageBox.Show("Age is: " + numericUpDown1.Value.ToString());
    }
    else
    {
       MessageBox.Show("The customer is ineligible for a senior citizen discount.");
    }
    
    if (Decimal.Compare(numericUpDown1.get_Value(), new Decimal(65)) >= 0)
    {
       MessageBox.Show(("Age is: " + numericUpDown1.get_Value().ToString()));
    }
    else
    {
       MessageBox.Show("The customer is ineligible for a senior citizen discount.");
    }
    
    if(numericUpDown1->Value >= 65)
    {
       MessageBox::Show(String::Concat("Age is: ",
          numericUpDown1->Value.ToString()));
    }
    else
    {
       MessageBox::Show
          ("The customer is ineligible for a senior citizen discount.");
    }
    

See Also

Reference

NumericUpDown Control Overview (Windows Forms)
NumericUpDown Class
NumericUpDown.Value Property
NumericUpDown.Increment Property
NumericUpDown.UpButton Method
NumericUpDown.DownButton Method

Other Resources

NumericUpDown Control (Windows Forms)