In my form, I created two panels panel1 and panel2, within each panel I created one button named button1 and button2 respectively. if I want to add event handler using,
this.button1.Click += buttonEvent;
is fine. But, when I use foreach for each controls in form, It is not detected. Whats the problem here?
public myForm1()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
TextBox tb = c as TextBox;
if (tb != null)
{
tb.TextChanged += textChanged;
}
}
}
How can I access the control in each of my panel using foreach?