Represents a Windows up-down control that displays numeric values.
Object
MarshalByRefObject
MarshalByRefComponent
Control
RichControl
ScrollableControl
ContainerControl
UpDownBase
NumericUpDown
[Visual Basic] Public Class NumericUpDown Inherits UpDownBase Implements ISupportInitialize [C#] public class NumericUpDown : UpDownBase, ISupportInitialize [C++] public __gc class NumericUpDown : public UpDownBase, ISupportInitialize [JScript] public class NumericUpDown extends UpDownBase, ISupportInitialize
A NumericUpDown control contains a single numeric value that can be incremented or decremented by clicking the up or down buttons of the control. The user may also enter in a value, unless the ReadOnly property is set to true.
The numeric display may be formatted by setting the DecimalPlaces, Hexadecimal, or ThousandsSeparator properties. To display hexadecimal values in the control, set the Hexadecimal property to true. To display a thousands separator in decimal numbers when appropriate, set the ThousandsSeparator property to true. To specify the number of digits displayed after the decimal symbol, set the DecimalPlaces propertry to the number of decimal places to display.
To specify the allowable range of values for the control, set the Minimum and Maximum properties. Set the Increment value to specify the value to be incremented or decremented to the Value property when the user clicks the up or down arrow buttons.
When the UpButton or DownButton methods are called, either in code or by the click of the up or down buttons, the new value is validated and the control updated with the new value in the appropriate format. Specifically, if UserEdit is set to true, ParseEditText is called prior to validating or updating the value. The value is then verified to be between the Minimum and Maximum values and the UpdateEditText method is called.
Namespace: System.WinForms
Assembly: System.WinForms.dll
The following example instantiates 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 OnClick events have been instantiated. On the OnClick event of each check box, the DecimalPlaces, ThousandsSeparator and Hexadecimal properties are set, respectively.
[Visual Basic]
' Instantiate a NumericUpDown control. Private NumericUpDown1 As System.WinForms.NumericUpDown Public Sub MySub() ' Initialize the NumericUpDown control. NumericUpDown1 = New System.WinForms.NumericUpDown Form1.Controls.Add(NumericUpDown1) NumericUpDown1.BeginInit ' Dock the control to the top of the form. NumericUpDown1.Dock = System.WinForms.DockStyle.Top ' Set the Minimum, Maximum and the initial Value. NumericUpDown1.Value = 5 NumericUpDown1.Maximum = 2500 NumericUpDown1.Minimum = -100 NumericUpDown1.EndInit End Sub ' Check box to toggle decimal places to be displayed. Private Sub CheckBox1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) ' 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 Then NumericUpDown1.DecimalPlaces = 0 NumericUpDown1.Value = Round(NumericUpDown1.Value, 0) Else NumericUpDown1.DecimalPlaces = 2 NumericUpDown1.Increment = 0.25 End If End Sub ' Check box to toggle thousands separators to be displayed. Private Sub CheckBox2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) ' If ThousandsSeparator is true, set it to False; otherwise se it to true. If NumericUpDown1.ThousandsSeparator = True Then NumericUpDown1.ThousandsSeparator = False Else NumericUpDown1.ThousandsSeparator = True End If End Sub ' Check box to toggle hexadecimal to be displayed. Private Sub CheckBox3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) ' If Hexadecimal is true, set it to False; otherwise se it to true. If NumericUpDown1.Hexadecimal = True Then NumericUpDown1.Hexadecimal = False Else NumericUpDown1.Hexadecimal = True End If End Sub
NumericUpDown Members | System.WinForms Namespace | UpDownBase | ISupportInitialize | DomainUpDown