NumericUpDown.Increment Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the value to increment or decrement the spin box (also known as an up-down control) when the up or down buttons are clicked.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Public Property Increment As Decimal

Property Value

Type: System.Decimal

The value to increment or decrement the Value property when the up or down buttons are clicked on the spin box. The default value is 1.

Exception Condition
ArgumentOutOfRangeException

The assigned value is not greater than or equal to zero.

Clicking the up button causes the Value property to increment by the amount specified by the Increment property and approach the Maximum property. Clicking the down button causes the Value property to be decremented by the amount specified by the Increment property and approach the Minimum property.

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 Sub 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)
End Sub    

' Check box to toggle decimal places to be displayed.
Private Sub checkBox1_Click(sender As Object, e As 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 = Decimal.Round(numericUpDown1.Value, 0)
    Else
        numericUpDown1.DecimalPlaces = 2
        numericUpDown1.Increment = 0.25D
    End If
End Sub    

' Check box to toggle thousands separators to be displayed.
Private Sub checkBox2_Click(sender As Object, e As EventArgs)
    ' If ThousandsSeparator is true, set it to false;
    ' otherwise, set it to true. 
    If numericUpDown1.ThousandsSeparator Then
        numericUpDown1.ThousandsSeparator = False
    Else
        numericUpDown1.ThousandsSeparator = True
    End If
End Sub    

' Check box to toggle hexadecimal to be displayed.
Private Sub checkBox3_Click(sender As Object, e As EventArgs)
    ' If Hexadecimal is true, set it to false;
    ' otherwise, set it to true. 
    If numericUpDown1.Hexadecimal Then
        numericUpDown1.Hexadecimal = False
    Else
        numericUpDown1.Hexadecimal = True
    End If
End Sub

.NET Framework
Available since 1.1
Return to top
Show: