C# 通过反射获取winform上的控件
程序员文章站
2022-06-29 08:52:55
比如获取Button按钮: System.Reflection.FieldInfo[] fieldInfo = form.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingF ......
比如获取button按钮:
system.reflection.fieldinfo[] fieldinfo = form.gettype().getfields(system.reflection.bindingflags.nonpublic |
system.reflection.bindingflags.instance);
for (int i = 0; i < fieldinfo.length; i++)
{
switch (fieldinfo[i].fieldtype.name)
{
case "button":
{
button btn= (button)fieldinfo[i].getvalue(form);
break;
}
}
}