I'm trying to determine from my 2 dynamic buttons who click the event handler.
How i create my 2 dynamic buttons at Form load
private void Form1_Load(object sender, EventArgs e)
{
for (int q = 0; q < 2; q++)
{
Point newLoc = new Point(a, b);
for (int i = 0; i <= 3 - 1; i++)
{
buttonArray[i] = new Button();
buttonArray[i].Size = new Size(95, 80);
buttonArray[i].Name = "btn" + q;
buttonArray[i].Text = "btn" + q;
buttonArray[i].Click += newButton;
buttonArray[i].Location = newLoc;
a = a + 10;
if (a > 300)
{
b = b + 100;
a = 1;
}
this.Controls.Add(buttonArray[i]);
}
}
}
The Event I'm trying to call
void newButton(object sender, EventArgs e)
{
if (sender == "btn1")
{
MessageBox.Show("btn1");
}
if (sender == "btn2")
{
MessageBox.Show("btn2");
}
}
It can call the event handler if I do not add the IF statement.