none
NumericUpDown VALUE RRS feed

  • Question

  • This tool was used to drag the user to certain numbers that he inserted from 5 to 20 ONLY

    My problem is the possibility of writing decimal numbers and I do not want that
    - The other problem is that the user can write large numbers LIKE 1000 and does not do the maximum number except to exit the tool


    LOAD

    NUMTAX.Increment = 1 NUMTAX.Maximum = 20 NUMTAX.MINIMUM = 5

    ''''''''''

    Private Sub NUMTAX_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles NUMTAX.KeyPress
            On Error Resume Next
            If (Not e.KeyChar = ChrW(Keys.Back) And (".").IndexOf(e.KeyChar) = -1) Then
                e.Handled = False
            End If
        End Sub

        Private Sub NUMTAX_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NUMTAX.ValueChanged
            On Error Resume Next
            If NUMTAX.Value > 20 Then
                NUMTAX.Value = 20
            End If
        End Sub


    Monday, July 16, 2018 6:56 PM

Answers

  •  You are trying to work against the way the NumericUpDown control was designed to work.  The user can type whatever they want into the NUD but,  the number is not validated until the text area is loosing focus.  It is done like this because,  the NUD does not have a clue if the user is done typing a number until the control looses focus.

     It would require a bunch of cobble-job coding to try making it work the way you want.  Your best and easiest bet is to set the ReadOnly property to True so that the user can only change the value by using the Up/Down buttons or the Mouse Wheel.  They will not be able to type the number in.

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            NumericUpDown1.Minimum = 5
            NumericUpDown1.Maximum = 20
            NumericUpDown1.DecimalPlaces = 0
            NumericUpDown1.ReadOnly = True
            NumericUpDown1.BackColor = Color.White 'so the control is not gray from setting the ReadOnly property
        End Sub
     

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, July 16, 2018 10:19 PM
    • Marked as answer by ahmeddc Monday, July 16, 2018 10:26 PM
    Monday, July 16, 2018 10:11 PM

All replies

  • Set the decimalplaces property to 0

    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.

    Monday, July 16, 2018 6:59 PM
    Moderator
  • decimalplaces property = 0 virtually

    except to exit the tool


    • Edited by ahmeddc Monday, July 16, 2018 7:10 PM
    Monday, July 16, 2018 7:08 PM
  • decimalplaces property = 0 virtually

    except to exit the tool



    Sorry but you'll have to try to better explain the problem.  If the NumericUpDown has DecimalPlaces set to 0 and Maximum set to 20, then the user cannot enter fractional number or values greater than 20.  You do not need any additional code to enforce this (you shouldn't need either of the event handlers you posted).

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, July 16, 2018 8:08 PM
    Moderator
  •  You are trying to work against the way the NumericUpDown control was designed to work.  The user can type whatever they want into the NUD but,  the number is not validated until the text area is loosing focus.  It is done like this because,  the NUD does not have a clue if the user is done typing a number until the control looses focus.

     It would require a bunch of cobble-job coding to try making it work the way you want.  Your best and easiest bet is to set the ReadOnly property to True so that the user can only change the value by using the Up/Down buttons or the Mouse Wheel.  They will not be able to type the number in.

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            NumericUpDown1.Minimum = 5
            NumericUpDown1.Maximum = 20
            NumericUpDown1.DecimalPlaces = 0
            NumericUpDown1.ReadOnly = True
            NumericUpDown1.BackColor = Color.White 'so the control is not gray from setting the ReadOnly property
        End Sub
     

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, July 16, 2018 10:19 PM
    • Marked as answer by ahmeddc Monday, July 16, 2018 10:26 PM
    Monday, July 16, 2018 10:11 PM
  •  You are trying to work against the way the NumericUpDown control was designed to work.  The user can type whatever they want into the NUD but,  the number is not validated until the text area is loosing focus.  It is done like this because,  the NUD does not have a clue if the user is done typing a number until the control looses focus.

     It would require a bunch of cobble-job coding to try making it work the way you want.  Your best and easiest bet is to set the ReadOnly property to True so that the user can only change the value by using the Up/Down buttons or the Mouse Wheel.  They will not be able to type the number in.

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            NumericUpDown1.Minimum = 5
            NumericUpDown1.Maximum = 20
            NumericUpDown1.DecimalPlaces = 0
            NumericUpDown1.ReadOnly = True
            NumericUpDown1.BackColor = Color.White 'so the control is not gray from setting the ReadOnly property
        End Sub
     

     


    If you say it can`t be done then i`ll try it

    Thank you so much this is required
    Monday, July 16, 2018 10:26 PM