[英]How do I get the values from a dynamically created 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 = 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);
}
使用窗体的Control集合访问控件,并将其传递给numericUpDown
控件的名称:
var numericUpDown = this.Controls["note0"] as NumericUpDown;
if(numericUpDown != null)
{
var value = numericUpDown.Value;
}
您仍然可以使用ValueChanged事件:
...
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.