如何:使用 Windows 窗体 NumericUpDown 控件设置和返回数值
Windows 窗体 NumericUpDown 控件的数值由其 Value 属性确定。 可以像编写任何其他属性一样为控件的值编写条件测试。 设置 Value 属性后,可以通过编写代码直接对其进行调整以对其执行操作,也可以调用 UpButton 和 DownButton 方法。
设置数值
在代码或“属性”窗口中为 Value 属性赋值。
NumericUpDown1.Value = 55
numericUpDown1.Value = 55;
numericUpDown1->Value = 55;
- 或者 -
调用 UpButton 或 DownButton 方法,以增加或减少 Increment 属性中指定的量。
NumericUpDown1.UpButton()
numericUpDown1.UpButton();
numericUpDown1->UpButton();
返回数值
访问代码中的 Value 属性。
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."); }
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈