Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Setting and Returning Numeric Values With the Windows Forms NumericUpDown Control

Visual Studio .NET 2003

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

  • Assign a value to the Value property in code or in the Properties window.
    ' Visual Basic
    NumericUpDown1.Value = 55
    
    // C#
    numericUpDown1.Value = 55;
    
    // C++
    numericUpDown1->Value = 55;
    

    -or-

  • Call the UpButton or DownButton method to increase or decrease the value by the amount specified in the Increment property.
    ' Visual Basic
    NumericUpDown1.UpButton()
    
    // C#
    numericUpDown1.UpButton();
    
    // C++
    numericUpDown1->UpButton();
    

To return the numeric value

  • Access the Value property in code.
    ' Visual Basic
    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
    
    // C#
    if(numericUpDown1.Value >= 65)
    {
       MessageBox.Show("Age is: " + numericUpDown1.Value.ToString());
    }
    else
    {
       MessageBox.Show("The customer is ineligible for a senior citizen discount.");
    }
    
    // C++
    if(numericUpDown1->Value >= 65)
    {
       MessageBox::Show(String::Concat(S"Age is: ",
          numericUpDown1->Value.ToString()));
    }
    else
    {
       MessageBox::Show
          (S"The customer is ineligible for a senior citizen discount.");
    }
    

See Also

NumericUpDown Control (Windows Forms) | Introduction to the Windows Forms NumericUpDown Control | NumericUpDown Class | NumericUpDown.Value Property | NumericUpDown.Increment Property | NumericUpDown.UpButton Method | NumericUpDown.DownButton Method

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.