---
title: "How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?"  
description: "How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?"  
author: "Anonymous User"  
published: 2014-01-22  
updated: 2014-01-23  
canonical: https://www.mindstick.com/forum/1856/how-to-get-all-child-controls-of-a-windows-forms-form-of-a-specific-type-button-textbox  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?

I need to get all [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) on a [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) that are of type x. I'm pretty sure I saw that [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) once in the [past](https://www.mindstick.com/articles/13129/great-tools-for-continuing-your-education-past-college) that used something like this:

[dim](https://www.mindstick.com/interview/561/what-is-the-difference-between-the-dim-public-and-private-statements) ctrls() as [Control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control)

ctrls = Me.Controls(GetType([TextBox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview)))

I know I can iterate over all controls getting [children](https://yourviews.mindstick.com/view/81386/mobile-app-based-education-curse-or-boon-for-our-children) using a [recursive function](https://www.mindstick.com/forum/156808/write-a-program-for-making-recursive-function-in-any-language), but is there something easier or more straightforward, maybe like the following?

Dim Ctrls = From ctrl In Me.Controls Where ctrl.GetType Is Textbox

## Replies

### Reply by Pravesh Singh

Hi Ashish,

This is an improved version of the recursive GetAllControls() that actually works on private vars:

```
    private void Test()    {        
List<Control> allTextboxes = GetAllControls(this);    }    private List<Control> GetAllControls(Control container, List<Control> list)    {        foreach(Control c in container.Controls)        {            if (c is TextBox) list.Add(c);            if(c.Controls.Count > 0)                list =GetAllControls(c, list);        }        return list;    }    privateList<Control> GetAllControls(Control container)    {        return GetAllControls(container, new List<Control>());    }
```


---

Original Source: https://www.mindstick.com/forum/1856/how-to-get-all-child-controls-of-a-windows-forms-form-of-a-specific-type-button-textbox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
