Hi I'm trying to iterate through controls from main form. I'm getting 2 controls while I'm expecting 4. Here's my code so far
C# Code:
public Object GetOption()
{
Object o = new Object();
Control con = new Control();
Size size = new Size
{
Width = 90,
Height = 12
};
CheckBox checkBox = new CheckBox
{
Name = "SomeCheckBox",
Checked = true,
Location = new Point(p.X, p.Y),
Size = size
};
ComboBox comboBox = new ComboBox
{
Name = "SomeComboBox",
Text = "Some text in CB",
Location = new Point(Convert.ToInt32(p.X + 25), p.Y),
Size = size
};
TextBox count = new TextBox
{
Name = "CountTextBox",
Text = "20",
Size = size,
Location = new Point(Convert.ToInt32(p.X + 25), p.Y)
};
TextBox date = new TextBox
{
Name = "DateNow",
Text = System.DateTime.Now.ToString("dd.MM.yyyy"),
Size = size,
Location = new Point(Convert.ToInt32(p.X + 25), p.Y)
};
con.Controls.AddRange(new Control[] { checkBox, comboBox, count, date });
// Next position
p.X = 25;
p.Y = p.Y + 14;
o = con;
return o;
}
EDIT: I forgot to give the loop
C# Code:
private void Button1_Click(object sender, EventArgs e)
{
Control control = new Control();
control = (Control)GetOption();
foreach (Control c in control.Controls)
{
MessageBox.Show("Type of control: " + c.GetType().ToString());
Options_Pnl.Controls.Add(c);
}
}