如何设置 Windows 窗体 NumericUpDown 控件的格式化

可以配置 Windows 窗体 NumericUpDown 控件中值的显示方式。 该 DecimalPlaces 属性确定小数点后显示的数字数;默认值为 0。 该 ThousandsSeparator 属性确定是否在每三个十进制数字之间插入分隔符;默认值为 false。 如果该 Hexadecimal 属性设置为 true,控件可以显示十六进制而不是十进制格式的值;默认值为 false

设置数值的格式

  • 通过将DecimalPlaces属性设置为整数,并将ThousandsSeparator属性设置为truefalse来显示十进制值。

    NumericUpDown1.DecimalPlaces = 2
    NumericUpDown1.ThousandsSeparator = True
    
    numericUpDown1.DecimalPlaces = 2;
    numericUpDown1.ThousandsSeparator = true;
    
    numericUpDown1->DecimalPlaces = 2;
    numericUpDown1->ThousandsSeparator = true;
    

    -或-

  • Hexadecimal 属性设置为 true 来显示十六进制值。

    NumericUpDown1.Hexadecimal = True
    
    numericUpDown1.Hexadecimal = true;
    
    numericUpDown1->Hexadecimal = true;
    

    注释

    即使该值在窗体中以十六进制形式显示,对 Value 属性进行的所有测试实际上是针对其十进制值的。

另请参阅