[C#] Hello, I have a little problem with my program. I'm creating textboxes and a button each time a button is pressed. I want to create a method for each button through loop, and later on, be able to call that method so that when the button gets clicked, the textboxes and the button itself are deleted. How do I create these methods? How do I call each one of these respectively to button names(e.g button01, button02... button35) in a loop? I made one to test it but it does not work. Could anyone point me in a right direction? What to do?
TextBox fieldA = new TextBox();
fieldA.Name = "fieldA" + i;
fieldA.Text = "fieldA"+i;
fieldA.Location = new Point(x[0], y[i]);
Controls.Add(fieldA);
textBoxListA[i] = fieldA;
Button buttonA = new Button();
buttonA.Name = "button" + i; // its name is button0
buttonA.Text = "button" + i;
buttonA.Location= new Point(x[3], y[i]);
Controls.Add(buttonA);
private void button0_Click(object sender, EventArgs e)] // im trying to call it but it wont work
{
//code to delete textboxes and this button
}