1
votes

I have a NumericUpDown where up and down arrows are there to enter integer. All that is set up but I want to disable entering the value manually by clicking. I want the user to be able to change value only via up and down arrow. can someone guide me how to achieve that.

enter image description here

Currently I have added ValueChanged Event to handle some of the logic. But that event does not get triggered when the value is manualy changed. Please guide me.

enter image description here

2
What does "UI Control" mean? A UserControl? Custom Control? That looks like and sounds like a NumericUpDown, is that what it is?Ňɏssa Pøngjǣrdenlarp
Numeric Up Down ControlUnbreakable
It does get fired when the user leaves the control - until then any value is just tentative. No matter how they enter a value, it will be forced to be between Min and Max, so why do you need to disable typing? Also, the resulting Value will be a DecimalŇɏssa Pøngjǣrdenlarp
This is contrary to the design of the control. If you don't want the behavior of a NumericUpDown, then why use one? Just use a textbox, disable entry, and handle the key presses to increment and decrement.DonBoitnott
@DonBoitnott The OP wants the mouse to do the work only.LarsTech

2 Answers

3
votes

This will fire every time someone presses a key when the control has focus.

Private Sub NumericUpDown1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles NumericUpDown1.KeyPress
    e.Handled = True
End Sub

All it does is effectively intercept the keypress, and tell the system that the keypress has been deal twith in your sub, and no further processing of the keypress will happen.

3
votes

In addition to handling key events, you can make the edit part of the control readonly:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    DirectCast(Me.NumericUpDown1.Controls(1), TextBox).ReadOnly= True
    DirectCast(Me.NumericUpDown1.Controls(1), TextBox).BackColor= Color.White
End Sub

NumericUpDown is a composite control consisting a custom TextBox and a custom control for Buttons part. You can do anything with those controls. Handling those events, changing properties and so on.