C# 如何从动态创建的NumericUpDown中获取值?
如何在C#中从动态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 =
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
}