Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从动态创建的NumericUpDown中获取值?_C#_Winforms_Numericupdown - Fatal编程技术网

C# 如何从动态创建的NumericUpDown中获取值?

C# 如何从动态创建的NumericUpDown中获取值?,c#,winforms,numericupdown,C#,Winforms,Numericupdown,如何在C#中从动态NumericUpDown获取值 这是我的密码 for (int i=0; i<n;i++) { NumericUpDown notele = new NumericUpDown(); notele.Name = "note" + i.ToString(); notele.Location = new System.Drawing.Point(280, 208 + (30 * i)); notele.Size =

如何在C#中从动态
NumericUpDown
获取值

这是我的密码

for (int i=0; i<n;i++)
{
    NumericUpDown notele = new NumericUpDown();
    notele.Name = "note" + i.ToString();              
    notele.Location = new System.Drawing.Point(280, 208 + (30 * i));
    notele.Size = new System.Drawing.Size(40, 25);
    notele.BackColor = System.Drawing.SystemColors.ControlDark;
    notele.Maximum = new decimal(new int[] {10,0,0, 0});
    this.Controls.Add(notele);
}

for(int i=0;i使用窗体的访问控件,并向其传递
numericUpDown
控件的名称:

var numericUpDown  = this.Controls["note0"] as NumericUpDown;

if(numericUpDown != null)
{
   var value = numericUpDown.Value;
}
您仍然可以利用该活动:

...
    notelle.ValueChanged += UpDnValueChangedHandler;

    this.Controls.Add(notele);
}

private void UpDnValueChangedHandler(object sender, EventArgs e)
{
    // sender references the control which value was changed:
    NumericUpDown notelle = sender as NumericUpDown;

    // further processing goes here
}