Click here to Skip to main content
6,306,412 members and growing! (21,585 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Beginner License: The Code Project Open License (CPOL)

NumericUpDown with unit measure

By CTR (centro-tecnologia-rocci)

How to create NumericUpDown control with unit measure. Support Vista Styles!
VB 8.0.NET 2.0, Win2K, WinXP, Win2003, Vista, WinForms, VS2005, Dev
Posted:28 Jul 2006
Updated:17 Jun 2007
Views:18,361
Bookmarked:25 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
14 votes for this article.
Popularity: 4.23 Rating: 3.69 out of 5
2 votes, 14.3%
1
1 vote, 7.1%
2

3
4 votes, 28.6%
4
7 votes, 50.0%
5

Screenshot - UpDownEx_with_measure.jpg

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

Introduction

This control is an evolution of the classic control numericUpDown. The control numericUpDown visualizes and returns through property value, a decimal value, but, what if we need to increment a numeric value specifying also the measure? To this point our UpDownEx control enters in 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 3 decimal digits, the increment will be in 0.001. Plus every steps in the measure stair is automatic, either in increment or in decrement phases.

The code

The UpDownEx code inherits "Control" class and includes a numercUpDown 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 += "#"
        Next
        str_Format += "0."
        For i = 0 To UpDown.DecimalPlaces - 1
            str_Format += "0"
        Next
        dbl_Value = UpDown.Value - (int_Factor * int_UnitsActual)
        Me.TextControl.Text = dbl_Value.ToString(str_Format) & " " & str_Units(int_UnitsActual)
    End Sub
Property

Screenshot - NewProperty.gif

Units of measure

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

Values

  • FormattedValues: Representing the value with the units of measure
  • UnformattedValues: Representing the value
Support Windows Vista Styles

Screenshot - vistaos.jpg

License

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

About the Author

CTR (centro-tecnologia-rocci)


Member
Web site www.lucarocci.it
Occupation: Web Developer
Location: Italy Italy

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralNumeric UpDown Control PinmemberMember 332006023:51 8 Sep '08  
JokeRe: Numeric UpDown Control PinmemberCTR (centro-tecnologia-rocci)23:27 14 Sep '08  
GeneralPretty... Pinmemberwout de zeeuw14:34 17 Jun '07  
GeneralRe: Pretty... PinmemberCTR (centro-tecnologia-rocci)1:31 18 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Jun 2007
Editor:
Copyright 2006 by CTR (centro-tecnologia-rocci)
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project