Giving NumericUpDown Events in Flow Layout Panel (C#)

106 views Asked by At

I'm using the following code to generate NumericUpDown's inside of a FlowLayoutPanel but I can't figure out how to add a Value Changed event handler.

        string numericUpDownText = "captchaNumericUpDown";
        NumericUpDown newNumericUpDown = new NumericUpDown();
        newNumericUpDown.Name = textboxID.ToString() + numericUpDownText;
        newNumericUpDown.Width = 50;
        itemFlowPanel.Controls.Add(newNumericUpDown);

I want all of them to do the same thing, but I'm not sure how to trigger the event. I've tried the following, but it didn't work either.

newNumericUpDown.ValueChanged = sylladexUpdate(sender, e);
1

There are 1 answers

3
Microsoft DN On BEST ANSWER

You need to add your code inside "ValueChanged" event handler.

NumericUpDown newNumericUpDown = new NumericUpDown();
newNumericUpDown.ValueChanged += new EventHandler(newNumericUpDown_ValueChanged);

And your event handler-

private void NumericUpDown1_ValueChanged(Object sender, EventArgs e) 
{    
    sylladexUpdate(sender, e); 
}