Click here to Skip to main content
13,504,533 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 28 Jul 2006

NumericUpDown with unit measure

Rate this:
Please Sign up or sign in to vote.
How to create a NumericUpDown control with unit measure. Support Vista styles!

Screenshot - UpDownEx_with_measure.jpg

This control was designed by CTR (centro-tecnologia-rocci), Rocci Luca & D'Andrea Vito


This control is an evolution of the classic control NumericUpDown. The control numericUpDown visualizes and returns through a property value, a decimal value, but what if we need to increment a numeric value also specifying the measure? At this point, our UpDownEx control enters the game. Our control returns a double value and visualizes a type value double and some text that indicates the measure. The increment is relative to the precision of the visualized number.

For example, if you enter a number with three decimal digits, the increment will be in 0.001. Plus every step in the measure stair is automatic, either in increment or in decrement phases.

The code

The UpDownEx code inherits the "Control" class and includes a NumericUpDown standard control and some properties like an Array that indicates the measures.

Private Sub Format()
    Dim str_Format As String
    If UpDown.Value = int_Factor * (int_UnitsActual) And int_UnitsActual > 0 Then
        int_UnitsActual -= 1
        UpDown.Value -= 1
        UpDown.DecimalPlaces -= 1
    ElseIf UpDown.Value = int_Factor * (int_UnitsActual + 1) And _
           int_UnitsActual < str_Units.Length Then
        int_UnitsActual += 1
        UpDown.Value += 1
        UpDown.DecimalPlaces += 1
    End If
    UpDown.Increment = dbl_Decimals(UpDown.DecimalPlaces)
    Dim i As Integer
    str_Format = "#,"
    For i = 0 To UpDown.DecimalPlaces - 1
        str_Format += "#"
    str_Format += "0."
    For i = 0 To UpDown.DecimalPlaces - 1
        str_Format += "0"
    dbl_Value = UpDown.Value - (int_Factor * int_UnitsActual)
    Me.TextControl.Text = dbl_Value.ToString(str_Format) & " " & str_Units(int_UnitsActual)
End Sub

Screenshot - NewProperty.gif

Units of measure

  • Factor: Represents the step between two units of measure
  • Maximum: Represents the max value
  • Minumum: Represents the min value
  • MeasureUnits: Represents an array of strings containing the units of measure


  • FormattedValues: Represents the value with the units of measure
  • UnformattedValues: Represents the value
Windows Vista styles are supported:

Screenshot - vistaos.jpg


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

QuestionGood Try Pin
Sabresite7-May-12 9:44
memberSabresite7-May-12 9:44 
GeneralMy vote of 2 Pin
Dave Kreskowiak8-Mar-10 14:57
mvpDave Kreskowiak8-Mar-10 14:57 
GeneralNumeric UpDown Control Pin
Member 33200608-Sep-08 22:51
memberMember 33200608-Sep-08 22:51 
JokeRe: Numeric UpDown Control Pin
CTR (centro-tecnologia-rocci)14-Sep-08 22:27
memberCTR (centro-tecnologia-rocci)14-Sep-08 22:27 
GeneralPretty... Pin
wout de zeeuw17-Jun-07 13:34
memberwout de zeeuw17-Jun-07 13:34 
GeneralRe: Pretty... Pin
CTR (centro-tecnologia-rocci)18-Jun-07 0:31
memberCTR (centro-tecnologia-rocci)18-Jun-07 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180417.1 | Last Updated 17 Jun 2007
Article Copyright 2006 by CTR (centro-tecnologia-rocci)
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid