سؤال

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?

هل كانت مفيدة؟

المحلول

numericUpDown.ReadOnly = true;

نصائح أخرى

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;
        }
    }

You may disable the CanFocus Property, so the user can´t focus the textarea but can click the up/down buttons.

numericUpDown1.CanFocus = false;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top