winform 查找控件并获取特定类型控件
程序员文章站
2022-12-25 17:10:56
感谢博主提供的思路https://blog.csdn.net/softimite_zifeng/article/details/54289012 ......
//通过反射获取所有控件集合 system.reflection.fieldinfo[] fieldinfo = this.gettype().getfields(system.reflection.bindingflags.nonpublic | system.reflection.bindingflags.instance); for (int i = 0; i < fieldinfo.length; i++) { //获取特定控件类型 if (fieldinfo[i].fieldtype.name != "contextmenustrip") continue; //通过名称获取控件 contextmenustrip cms = (contextmenustrip)fieldinfo[i].getvalue(this); }
感谢博主提供的思路https://blog.csdn.net/softimite_zifeng/article/details/54289012