NumericUpDown Text Event

I am using Microsoft Visual C # 2010 Express. When I change the value of numericUpDown with the arrows, my button becomes on. But I also want to turn on 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; } 
+8
c # visual-studio-2010 winforms numericupdown
source share
1 answer

You may need to use TextChanged instead of using ValueChanged . The value-changed event requires you to press the enter key after changing the value to get a ValueChanged value.

What MSDN says about the NumericUpDown.ValueChanged Event

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

Binding a TextChanged event.

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

TextChanged event declaration.

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

All Articles