public partial class Form1 : Form
{
int row, col;
int num = 0;
public Form1()
{
InitializeComponent();
}
private void generatebutton_Click(object sender, EventArgs e)
{
int rows = Convert.ToInt32(rowBox.Text);
int cols = Convert.ToInt32(colBox.Text);
for (int i = 2; i <= rows+1; i++)
{
for (int j = 4; j <= cols+3; j++)
{
Button button = new Button();
button.Location = new Point(j * 100, i * 100);
this.Controls.Add(button);
num++;
button.Text = Convert.ToString(num);
button.Name = Convert.ToString("button" + num);
WireUp(button, "Click", "Clickbutton");
}
}
}
void WireUp(object o, string eventname, string methodname)
{
EventInfo ei = o.GetType().GetEvent(eventname);
MethodInfo mi = this.GetType().GetMethod(methodname, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
Delegate del = Delegate.CreateDelegate(ei.EventHandlerType, this, mi);
ei.AddEventHandler(o, del);
}
void Clickbutton(object sender, System.EventArgs e)
{
textBox1.Text = Convert.ToString(num);
}
now i have to print corresponding number on clicking button