NumericUpDown.ThousandsSeparator 属性

定义

获取或设置一个值,该值指示在适当的时候数字显示框(也称作 up-down 控件)中是否显示千位分隔符。

C#
public bool ThousandsSeparator { get; set; }

属性值

如果在适当的情况下在数字显示框中显示千位分隔符,则为 true;否则为 false。 默认值是 false

示例

下面的代码示例创建并初始化控件 NumericUpDown ,设置其一些常见属性,并允许用户在运行时更改其中的一些属性。 此代码假定已将三 CheckBox 个控件放置在窗体上,并且已实例化其 Click 事件的处理程序。 、 DecimalPlacesThousandsSeparatorHexadecimal 属性在每个检查框的 事件上Click设置。

C#
public void InstantiateMyNumericUpDown()
{
   // Create and initialize a NumericUpDown control.
   numericUpDown1 = new NumericUpDown();

   // Dock the control to the top of the form.
   numericUpDown1.Dock = System.Windows.Forms.DockStyle.Top;

   // Set the Minimum, Maximum, and initial Value.
   numericUpDown1.Value = 5;
   numericUpDown1.Maximum = 2500;
   numericUpDown1.Minimum = -100;
   
   // Add the NumericUpDown to the Form.
   Controls.Add(numericUpDown1);
}

// Check box to toggle decimal places to be displayed.
private void checkBox1_Click(Object sender,
                             EventArgs e)
{
   /* If DecimalPlaces is greater than 0, set them to 0 and round the 
      current Value; otherwise, set DecimalPlaces to 2 and change the 
      Increment to 0.25. */
   if (numericUpDown1.DecimalPlaces > 0)
   {
      numericUpDown1.DecimalPlaces = 0;
      numericUpDown1.Value = Decimal.Round(numericUpDown1.Value, 0);
   }
   else
   {
      numericUpDown1.DecimalPlaces = 2;
      numericUpDown1.Increment = 0.25M;
   }
}

// Check box to toggle thousands separators to be displayed.
private void checkBox2_Click(Object sender,
                             EventArgs e)
{   
   /* If ThousandsSeparator is true, set it to false; 
      otherwise, set it to true. */
   if (numericUpDown1.ThousandsSeparator)
   {
      numericUpDown1.ThousandsSeparator = false;
   }
   else
   {
      numericUpDown1.ThousandsSeparator = true;
   }
}

// Check box to toggle hexadecimal to be displayed.
private void checkBox3_Click(Object sender, 
                             EventArgs e)
{
   /* If Hexadecimal is true, set it to false; 
      otherwise, set it to true. */    
   if (numericUpDown1.Hexadecimal)
   {
      numericUpDown1.Hexadecimal = false;
   }
   else
   {
      numericUpDown1.Hexadecimal = true;
   }
}

注解

ThousandsSeparator设置 属性后,UpdateEditText将调用 方法以将旋转框的显示更新为新格式。

相应的千位分隔符由用户操作系统的区域设置决定。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅