vb.net 如何在 NumericUpDown 控件中显示空值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20707734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display an empty value in NumericUpDown control?
提问by user3123337
I have a Windows Forms application that includes NumericUpDowncontrol With Minimumand Maximumvalues set to (50:80) accordingly and step 1.
我有一个 Windows 窗体应用程序,其中包含NumericUpDown控件, Minimum并且Maximum值相应地设置为 (50:80) 和步骤 1。
When form loads the NumericUpDownshows 50.
当表单加载NumericUpDown显示 50。
I know that NumericUpDownis for picking numbers and numeric types and always has a value, but is there any way to make it show empty when form loads?
我知道这NumericUpDown是用于选择数字和数字类型并且总是有一个值,但是有什么方法可以让它在表单加载时显示为空?
回答by har07
You can't make default NumericUpDown control empty. NumericUpDown need a value to increase/decrease from. If 'empty' is only a matter of look empty when user see the form at first, then you can hack it by setting NumericUpDown's Text to empty:
您不能将默认的 NumericUpDown 控件设为空。NumericUpDown 需要一个值来增加/减少。如果“空”只是用户第一次看到表单时看起来空的问题,那么您可以通过将 NumericUpDown 的 Text 设置为空来破解它:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
NumericUpDown1.Text = ""
End Sub
With that NumericUpDown1 will look empty, but NumericUpDown1.Value is still 50.
有了这个 NumericUpDown1 看起来是空的,但 NumericUpDown1.Value 仍然是 50。

