我想找到一个名为“textBoxQH_N”的文本框,其中“_N”是 1..96 中的一个数字。
所以,我有这个代码:
String sTextBoxToFind = String.Format("textBoxQH{0}", QuarterHour);
TextBox tb = (TextBox)this.Controls.Find(sTextBoxToFind, true);
...但它给了我,“无法将类型 'System.Windows.Forms.Control[]' 转换为 'System.Windows.Forms.TextBox' ”
所以我更改了第二行以仅获取第一个返回的 val:
TextBox tb = (TextBox)this.Controls.Find(sTextBoxToFind, true)[0];
这似乎可行,但控件的 Name 属性不应该对其所有者是唯一的吗?IOW,Find() 应该只返回 0..1 个控件,对吧?