感謝博主提供的思路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