NumericUpDown::DecimalPlaces Property
Gets or sets the number of decimal places to display in the spin box (also known as an up-down control).
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System::Int32The number of decimal places to display in the spin box. The default is 0.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value assigned is less than 0. -or- The value assigned is greater than 99. |
When the DecimalPlaces property is set, the UpdateEditText method is called to update the spin box's display to the new format.
The appropriate decimal symbol is determined by the regional settings of the user's operating system.
The following code example creates and initializes a NumericUpDown control, sets some of its common properties, and allows the user to change some of these properties at run time. This code assumes three CheckBox controls have been placed on a form and handlers for their Click events have been instantiated. The DecimalPlaces, ThousandsSeparator, and Hexadecimal properties are set on the Click event of each check box.
public: void InstantiateMyNumericUpDown() { // Create and initialize a NumericUpDown control. numericUpDown1 = gcnew 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 ); } private: // Check box to toggle decimal places to be displayed. 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 = Decimal(0.25); } } // Check box to toggle thousands separators to be displayed. 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. 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; } }
Available since 1.1