我正在使用Microsoft Visual C#2010 Express。当我使用箭头更改numericUpDown的值时,我的按钮变为启用。但是当我通过直接更改文本来更改numericUpDown的值时,我也想启用我的按钮。
我使用以下代码:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
button1.Enabled = true;
}
答案 0 :(得分:18)
您可能需要使用TextChanged事件而不是ValueChanged
。值更改事件需要您在更改值后按Enter键以获取ValueChanged。
MSDN对NumericUpDown.ValueChanged
事件
要发生ValueChanged事件,可以更改Value属性 在代码中,通过单击向上或向下按钮,或通过用户输入 控件读取的新值。 当读取新值时 用户点击ENTER键或导航离开控件。如果 用户输入一个新值,然后单击向上或向下按钮, ValueChanged事件将发生两次,MSDN。
绑定TextChanged事件。
private void TestForm_Load(object sender, EventArgs e)
{
numericUpDown1.TextChanged += new EventHandler(numericUpDown1_TextChanged);
}
TextChanged事件声明。
void numericUpDown1_TextChanged(object sender, EventArgs e)
{
button1.Enabled = true;
}