共用方式為


如何:為 Windows Form NumericUpDown 控制項設定格式

您可以設定如何在 Windows Forms NumericUpDown 控制項中顯示值。 屬性 DecimalPlaces 會決定小數點之後出現多少個數字;預設值為 0。 屬性 ThousandsSeparator 會判斷分隔符號是否要插入每三個十進位數;預設值為 false 。 如果 Hexadecimal 屬性設定為 true ,則控制項可以顯示十六進位而非十進位格式的值;預設值為 false

格式化數值

  • 將 屬性設定為整數,並將 屬性 true 設定 DecimalPlacesThousandsSeparator 為 或 false ,以顯示十進位值。

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

    -或-

  • 將 屬性設定為 trueHexadecimal 以顯示十六進位值。

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

    注意

    即使值以十六進位形式顯示在表單上,您在 屬性上 Value 執行的任何測試都會測試其十進位值。

另請參閱