我有一个包含此GroupControl中的GroupControl的窗体,有一些控件。为GroupControl中的所有控件创建一个仅foreach循环
我想,当我点击一个按钮的THOS控件的属性更改为control.Properties.ReadOnly = false;
所以我创造了这个代码:
foreach (TextEdit te in InformationsGroupControl.Controls)
{
te.Properties.ReadOnly = false;
}
foreach (TextEdit te in InformationsGroupControl.Controls)
{
te.Properties.ReadOnly = false;
}
foreach (DateEdit de in InformationsGroupControl.Controls)
{
de.Properties.ReadOnly = false;
}
foreach (ComboBoxEdit cbe in InformationsGroupControl.Controls)
{
cbe.Properties.ReadOnly = false;
}
foreach (MemoEdit me in InformationsGroupControl.Controls)
{
me.Properties.ReadOnly = false;
}
foreach (CheckEdit ce in InformationsGroupControl.Controls)
{
ce.Properties.ReadOnly = false;
}
这是工作,但我要创建的每一个foreach循环控制。
我也试过这个
foreach (Control control in InformationsGroupControl.Controls)
{
control.Properties.ReadOnly = false;
}
但System.Windows.Forms.Control的不包含定义“属性”
我如何可以创建在所有控件一个唯一的foreach循环GroupControl?
尝试使用'dynamic'。查找MSDN如果你不知道它是什么。要使用它,只需用'动态控制'替换'Control control'。 – 2012-09-22 17:21:36
我不能使用动态类型,它给了我这个错误: '无法找到类型或命名空间名称'dynamic'(您是否缺少using指令或程序集引用?)' –
'dynamic' was introduced在'C#4'中。你使用什么版本? – 2012-09-22 17:51:33