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
Assign a value to the Value property in code or in the Properties window.
NumericUpDown1.Value = 55
numericUpDown1.Value = 55;
numericUpDown1->Value = 55;
-or-
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();
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(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
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Desktop feedback