1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private List<Control> myList = new List<Control>();
void GetAllControl(List<Control> controls, Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
controls.Add(control.Controls[i]);
GetAllControl(controls, control.Controls[i]);
}
}
public Form1()
{
InitializeComponent();
GetAllControl(myList, this);
// J'ajoute les noms dans une combobox
foreach (var item in myList)
{
cb.Items.Add(item.Name);
}
}
}
} |
Partager