.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
Clintonzz
arronlee
mattyclown
cathyhill345

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to find the controls recursively in a Form/Control

Posted By:Jean Paul       Posted Date: September 29, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.jeanpaulva.com/  

Usage: GetControlsRecursively(form);
 

 

private IList controlsList = new List();

public IEnumerable GetControlsRecursively(Control container)
{
            controlsList.Clear();
            FindControlsRecursively(container);

            return ControlsList;
}

private void FindControlsRecursively(Control container)
{
        foreach (Control control in container.Controls)
        {
                controlsList.Add(control);
                if (container.HasChildren)
                    FindControlsRecursively(control);
        }
}

 

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend