The example in this article describes how WinForm traverses all child controls of a form. Share to everyone for your reference, specific as follows:
<summary>///C # only traverse control child controls, do not traverse the sun control///when the control has child controls, you need to iterate recursively to list all the controls on the control///</summary>///<typeparam na Me= "T" > control type </typeparam>///<param name= "Control" > Controls to Traverse </param>///<param name= " Controlsname "> Control name </param>///<returns></returns> public static T getcontrol<t>
Control, String controlsname) where T:control {if (control = null) return null;
Control _control; for (int i = 0; i < control. Controls.Count; i++) {_control = control.
Controls[i];
if (_control = null) return null; if (_control.
Name = = Controlsname && _control is T) return (t) _control; if (_control.
HasChildren) {_control = getcontrol<t> (_control, controlsname);
if (_control!= null) return (T) _control;
} return null; ///<summary>///Traverse form All child controls///</summary>///<typeparam name= "T" > control type </typeparam>///<par Am name= "form" > Form name </param>///<param name= "Controlsname" > Control name </param>///<returns></returns> public static T
getcontrol<t> (Form form, String controlsname) where T:control {T _control = null; for (int i = 0; i < form. Controls.Count; i++) {_control = getcontrol<t> (form.
Controls[i], controlsname);
if (_control!= null) return _control;
return null;
}
Read more about C # Interested readers can view the site topics: "WinForm Control Usage Summary", "C # form Operation Tips Summary", "C # Common control usage Tutorial", "C # Programming Thread usage Tips", "C # Operation Excel Skills Summary", "C # Summary of operational skills in XML files, C # tutorial on data structure and algorithms, C # array operation techniques Summary, and C # Introduction to object-oriented Programming
I hope this article will help you with C # programming.