Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't allow text entry in numericUpDown

I have a WinForm in C# with an NumericUpDown Control on it. I want the Control to change its value only after clicking on its up or down arrow, and to block the manual text entries, is there a property of NumericUpDown to do this, or any other way to implement?

like image 344
Pablo Elias Avatar asked Oct 08 '12 08:10

Pablo Elias


2 Answers

numericUpDown.ReadOnly = true;
like image 118
Simon Brydon Avatar answered Sep 30 '22 18:09

Simon Brydon


Please find below code which meets your requirement and might solve your issue:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            numericUpDown1.KeyDown+=new KeyEventHandler(numericUpDown1_KeyDown);
        }

        void numericUpDown1_KeyDown(object sender, KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
            return;
        }
    }
like image 42
mihirj Avatar answered Sep 30 '22 19:09

mihirj