Don't allow text entry in numericUpDown
-
05-07-2021 - |
题
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;
不隶属于 StackOverflow