Introduction
When writing a simple application, I needed one of the numeric boxes to be read only, so I just changed the ReadOnly
property of NumericUpDown
to true
. But after a while, I noticed that I can change the value in it, not by typing, but by using the up and down buttons.
Solution
To save people time, I posted this article presenting a simple and fast solution to the problem:
public class FixedNumericUpDown : NumericUpDown
{
public override void DownButton()
{
if (ReadOnly)
return;
base.DownButton();
}
public override void UpButton()
{
if (ReadOnly)
return;
base.UpButton();
}
}
Enjoy!