Click here to Skip to main content
Click here to Skip to main content
Go to top

NumericUpDown with correct read-only behavior

, 10 Nov 2006
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

dr4cul4
Software Developer
Poland Poland
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.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberMember 864580517-Jul-13 5:05 
GeneralMy vote of 4 PinmemberToli Cuturicu19-Aug-10 5:14 
GeneralMight be even better PinmemberMillionsterNutzer21-May-10 10:05 
GeneralNumericUpDown.Increment = 0; PinmemberEugene Goryachev11-Apr-08 0:10 
GeneralFix without replacing the control Pinmemberlos.12-Jun-07 22:32 
GeneralRe: Fix without replacing the control PinmemberLemuel.Adane15-May-09 1:20 
Generaldisable updown-control Pinmemberjls1716-Nov-06 7:41 
AnswerRe: disable updown-control Pinmemberdr4cul416-Nov-06 21:27 
Generalcode style opinion PinmemberTornacious14-Nov-06 8:17 
QuestionMore readable? Pinmembernurgling10-Nov-06 6:04 
AnswerRe: More readable? PinmemberMarc Leger10-Nov-06 8:33 
AnswerRe: More readable? Pinmemberdr4cul411-Nov-06 2:14 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 Nov 2006
Article Copyright 2006 by dr4cul4
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid