Every control that derives from Control has a Text property, which is every control — however for some controls this property does not have a meaning.
To build the complete list of controls you need to iterate the Form's Controls collection and then, for each control within it, recursively iterate that control's Controls collection.
IList<Control> controlsOnForm = new List<Control>();
BuildControlsList(this.Controls, controlsOnForm);
private static void BuildControlsList(ControlCollection controls, IList<Control> listToPopulate)
{
foreach (Control childControl in controls)
{
listToPopulate.Add(childControl);
BuildControlsList(childControl.Controls, listToPopulate);
}
}
I'm not actually sure how you are going to differentiate between controls that have a useful Text property and those for which it is not used. Obviously one approach would be to exclude those controls that have an empty string for the Text property.
One can also do something similar for the menu (note that you will need to modify this somewhat if you are using the MainMenuStrip):
IList<Menu> menusOnForm = new List<Menu>();
if (this.Menu != null)
{
menusOnForm.Add(this.Menu);
BuildMenuList(this.Menu.MenuItems, menusOnForm);
}
private static void BuildMenusList(MenuItemCollection menuItems, IList<Menu> listToPopulate)
{
foreach (Menu menuItem in menuItems)
{
listToPopulate.Add(menuItem);
BuildMenusList(menuItem.MenuItems, listToPopulate);
}
}