devxlogo

GetAllControls – Retrieving all the controls inside a container and its sub-containers

GetAllControls – Retrieving all the controls inside a container and its sub-containers

' Returns an array with all the controls in the specified container control and ' its child containers' Example:'    ' print the name of all the controls on the form and its child container ' controls'    Dim ctl As Control'    For Each ctl In GetAllControls(Me)'        Debug.WriteLine(ctl.Name)'    NextFunction GetAllControls(ByVal container As Control) As Control()    Dim al As New ArrayList    Dim ctl As Control    For Each ctl In container.Controls        GetAllControlsHelper(ctl, al)    Next    Return al.ToArray(GetType(Control))End FunctionSub GetAllControlsHelper(ByVal container As Control, ByVal al As ArrayList)    ' add this control to the ArrayList    al.Add(container)    ' add all its child controls, by calling this routine recursively    Dim ctl As Control    For Each ctl In container.Controls        GetAllControlsHelper(ctl, al)    NextEnd Sub

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist