Winform controls were used to find the form or container control

        Often encountered in the project to generate dynamic control, dynamic display or hide the specified control, which would involve lookup control problems.

       Here the control Winform used to find the name of a form or container control method, as follows:

        /// <Summary>
            /// Get the name of the control by the control
            /// </ Summary>
            /// <param name = "strName"> </ param>
            /// <Returns> </ Returns>
            Private Control GetPbControl ( strName String)
            {
                String pbName = strName;
                return the GetControl (the this, pbName);
            }
            /// <Summary>
            /// Get the name of the control by the control
            /// </ Summary>
            /// <param name = "CT"> the control is on a container or form </ param>
            /// <param name = "name"> need to find the control name </ param>
            /// <returns a> </ returns a>
            public static Control GetControl(Control ct, string name)
            {
                Control[] ctls = ct.Controls.Find(name, false);
                if (ctls.Length > 0)
                {
                    return ctls[0];
                }
                else
                {
                    return null;
                }
            }

           Find controls Demo code is as follows:

            strPxName = "SoftKeyBoard";
                Control sk = GetPbControl(strPxName);
                if (sk == null)
                {
                    return;
                }

 

 

Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2011/10/25/2224217.html

Guess you like

Origin blog.csdn.net/weixin_34237596/article/details/93054093