Created
June 27, 2018 07:41
-
-
Save polarstars/a205be057ecdef6439c13e5ac373964d to your computer and use it in GitHub Desktop.
查找控件包含的子控件(特定类型T) #C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<T> FindControlByType<T>(this Control mainControl, bool getAllChild = false) where T : Control | |
{ | |
List<T> lt = new List<T>(); | |
for (int i = 0; i < mainControl.Controls.Count; i++) | |
{ | |
if (mainControl.Controls[i] is T) lt.Add((T)mainControl.Controls[i]); | |
if (getAllChild) lt.AddRange(FindControlByType<T>(mainControl.Controls[i], getAllChild)); | |
} | |
return lt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment