How to make NumericUpDown ReadOnly
Try the following in order to set the numeric up/down as read-only:
numericUpDown1.ReadOnly = true;
numericUpDown1.Increment = 0;
I hope it helps.
Another alternative is to subclass NumericUpDown
and override the DownButton
and UpButton
methods so they return early when ReadOnly
is set:
public override void DownButton()
{
if(this.ReadOnly)
return;
base.DownButton();
}
public override void UpButton()
{
if(this.ReadOnly)
return;
base.UpButton();
}
This appears to also prevent up/down arrow presses and mouse scrolls from changing the value.
The benefit of this approach is that you can now data bind the ReadOnly property on the control and expect it to make the value read-only instead of just the text area.