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!
Hi to all.
I’m a software developer who works in a small company. I started programming when I was 10 (or less, can't remember) on not mine C64 – those were the good times :P Now I’m coding mainly in C# / C++, but my favorite language is C.