我正在使用Microsoft Visual C# 2010学习版。当我使用箭头更改numericUpDown的值时,我的按钮变为启用。但是当我通过直接更改文本来更改numericUpDown的值时,我也想启用我的按钮。
我使用了以下代码:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
button1.Enabled = true;
}发布于 2013-07-09 15:51:51
您可能需要使用TextChanged事件而不是ValueChanged。Value changed事件需要您在更改value后按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;
}https://stackoverflow.com/questions/17542622
复制相似问题