How to Use Dynamically Created Button/textBox in C# Windows Forms?
c#, winforms
Solution
You can assign an event handler to the click event:
b.Click += SomeMethod;
`SomeMethod` must have the following signature:
void SomeMethod(object sender, EventArgs e)
Problem
``` private void createButton() { flowLayoutPanel1.Controls.Clear(); for (int i = 0; i < 4; i++) { Button b = new Button(); b.Name = i.ToString(); b.Text = "Button" + i.ToString(); flowLayoutPanel1.Controls.Add(b); } } private void button1_Click(object sender, EventArgs e) { createButton(); } ``` I Used this code to create some buttons on runtime , now how can i use those created buttons to perform diffrent actions? Im kindz new to this so please help me , very much appreciated :)