I'm using this code:
foreach (Control c in this.Controls)
{
Button btn = c as Button;
{
if (c == null)
continue;
c.Click += handle_click;
}
void handle_click(object sender, EventArgs e)
{
Form1 ss = new Form1();
ss.label1.Text = (sender as Button).Text;
ss.ShowDialog();
}
But the code influence all my Form elements. Example all my buttons. How can create an exception for one button? I manage that by creating a panel and place my button inside, but when i'm clicking on the panel i get this error message:
"NullReferenceExeption was unhandled" "Object reference not set to an instance of an object"
Why this happen?