Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

NumericUpDown with correct read-only behavior

0.00/5 (No votes)
10 Nov 2006 1  
A simple article showing another bug in .NET Framework 2.0.

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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here