我如何创建具有不同事件的按钮

How do i create buttons with different events

            for(int i = 0; i < 4; i++)
            {
                bttn = "b" + i;
                Button b = new Button
                {
                    Width= 100,
                    Name = "b" + i,
                    Text = "hey" + i,
                Location = new Point(centerLine.Location.X+i*100,centerLine.Location.Y),
                };
                b.Click += (sender1, e1) =>
                {
                    textBox1.Text += "wtf"+i;
                };
                this.Controls.Add(b);
            }

我遇到的问题是我不知道如何制作多个事件,我只有一个发送者,据我所知,发送者只是确定我的事件,所以在 for 循环结束时它将是等于我做的最后一个事件。

好的,所以我尝试创建 4 个带有事件的按钮。但问题是当我按下任何按钮时,事件是相同的,wtf4 被添加到文本框,就像最后一个按钮决定所有事件一样。中心线只是我拥有的一条线,可帮助我将这些按钮创建到特定位置。我如何使这些事件不同?

你必须得到发件人的名字

for(int i = 0; i < 4; i++)
{
    bttn = "b" + i;
    Button b = new Button
    {
        Width= 100,
        Name = "b" + i,
        Text = "hey" + i,
        Location = new Point(centerLine.Location.X+i*100,centerLine.Location.Y),
    };
    b.Click += (sender1, e1) =>
    {
        textBox1.Text += ((Button)sender1).Name;
    };
    this.Controls.Add(b);
}