TextChanged Event of NumericUpDown

情到浓时终转凉″ 提交于 2019-12-06 22:58:54

问题


I am using Microsoft Visual C# 2010 Express. When i change the value of numericUpDown using arrows, my button becomes enable. But i also want to enable my button when i change the value of numericUpDown by changing the text directly.

I am using the following code:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}

回答1:


You may need to use TextChanged event instead of using ValueChanged. The Value changed event need you to press enter key after changing value to get ValueChanged fired.

What MSDN say about NumericUpDown.ValueChanged Event

For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the control. The new value is read when the user hits the ENTER key or navigates away from the control. If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice, MSDN.

Binding TextChanged event.

private void TestForm_Load(object sender, EventArgs e)
{
    numericUpDown1.TextChanged += new EventHandler(numericUpDown1_TextChanged);
}

Declaration of TextChanged event.

void numericUpDown1_TextChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}


来源:https://stackoverflow.com/questions/17542622/textchanged-event-of-numericupdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!