【发布时间】:2013-09-10 12:08:28
【问题描述】:
我想添加一个动态的CheckAll() 方法来检查我的类中声明的所有复选框。
我尝试了以下代码:
class MyContol : UserControl
{
///
/// HIDDEN but there is plenty of checkboxes declaration
///
private void CheckAll()
{
FieldInfo[] props = this.GetType().GetFields();
foreach (FieldInfo p in props)
{
if (p.FieldType is CheckBox)
{
/// TODO: Check my box
}
}
}
}
...但是props 是空的。我不知道如何定位使用设计器部分制作的复选框。
你知道使用Reflection如何通过设计视图组件添加目标吗?
【问题讨论】:
-
我用this
-
@Sayse,很有趣。
标签: c# winforms reflection user-controls