winform 查找控件并获取特定类型控件

            //通过反射获取所有控件集合
            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

posted @ 2018-09-26 09:12 潇洒今生 阅读(...) 评论(...) 编辑 收藏