private Control FindControl(Control container, string controlName)  // 参数1为容器 参数2为控件名称
        {
          if (container.Name == controlName)
            {
              return container;
             }
            Control findControl = null;
            foreach (Control control in container.Controls)
            { Console.WriteLine(control.Name);
                if (control.Controls.Count == 0)
                {
                    if (control.Name == controlName)
                    {
                        findControl = control; break;
                    }
                }
                else
                {
                    findControl = FindControl(control, controlName);
                    if (findControl != null)
                    {
                        break;
                    }
                }
            }
            return findControl;
        }

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐