Click here to Skip to main content
Licence CPOL
First Posted 10 Nov 2006
Views 26,574
Bookmarked 8 times

NumericUpDown with correct read-only behavior

By | 10 Nov 2006 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

dr4cul4

Software Developer

Poland Poland

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberToli Cuturicu5:14 19 Aug '10  
GeneralMight be even better PinmemberMillionsterNutzer10:05 21 May '10  
GeneralNumericUpDown.Increment = 0; PinmemberEugene Goryachev0:10 11 Apr '08  
GeneralFix without replacing the control Pinmemberlos.22:32 12 Jun '07  
GeneralRe: Fix without replacing the control PinmemberLemuel.Adane1:20 15 May '09  
Generaldisable updown-control Pinmemberjls177:41 16 Nov '06  
AnswerRe: disable updown-control Pinmemberdr4cul421:27 16 Nov '06  
Generalcode style opinion PinmemberTornacious8:17 14 Nov '06  
QuestionMore readable? Pinmembernurgling6:04 10 Nov '06  
AnswerRe: More readable? PinmemberMarc Leger8:33 10 Nov '06  
AnswerRe: More readable? Pinmemberdr4cul42:14 11 Nov '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 10 Nov 2006
Article Copyright 2006 by dr4cul4
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid