I have created two UserControls in my WinFroms Application. Some more UserControls will be created.
Now I want to get a list of my created UserControls by name.
For example:
UserControl ctrl1
UserControl ctrl2
UserControl ctrl3
The UserControls are created like this:
namespace Test.Controlls
{
public partial class ctrl1 : UserControl
{
On my WinForms Application it will be included like this:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
contrctrl1.Visible = true;
contrctrl1.BringToFront();
Now I want ot get the names ctrl1, ctrl2 and ctrl3 in a list to loop through it afterwards.
Something like this:
List<> ctrllist = new List<>();
ctrllist.Add();
for (int i =0; <ctrllist>.count; i++)
{
switch (ctrllist.toString())
{
case "ctrl1": //do seomething
break;
case "ctrl2": //do seomething
break;
case "ctrl2": //do seomething
break;
}
}
Please help me to find a solution.
Thank you.
EDIT: I don't want to know textbox, button controls etc. I have created by own UserControl "Form" and want to store these Names in a list or datatable to retreive back the names if needed.