Question limiting NumericUpDown control

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I need to make a NumericUpDown control with extremely limited functionality. It should not possible for the user to type in the value - the only way it changes is to use the up and down buttons.

I tried to make the standard control read-only, but it still accepts the cursor into the entry box.

Any suggestions :confused:
 
This will allow only the spinner buttons to be clicked and it will allow the user to use the up and down arrow keys only:
VB.NET:
    Private Sub NumericUpDown1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NumericUpDown1.KeyDown
        e.Handled = (e.KeyCode <> Keys.Up AndAlso e.KeyCode <> Keys.Down)
    End Sub

    Private Sub NumericUpDown1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericUpDown1.KeyPress
        e.Handled = Char.IsDigit(e.KeyChar)
    End Sub
 
Thanks Juggalo. That worked, but didnt do exactly what I wanted. In the end, I wrote my own control :)
 
Back
Top