我正在使用C#窗体并需要一些帮助。我有一个按钮可以创建其他按钮并将它们添加到列表的“按钮”中。我需要让每个按钮在点击时自行销毁。删除动态生成的按钮
//create new button
Button newButton = new Button();
newButton.Name = "aButt"+buttNum;
Debug.WriteLine(newButton.Name);
buttNum++;
newButton.Text = "Button!";
newButton.Height = 50;
newButton.Width = 50;
//controls where the new button gets placed
if (curX > 9)
{
curX = 0;
curY++;
//defines the point the button spawns
newButton.Location = new System.Drawing.Point((curX * 55)+10, curY * 55);
//increments X to avoid placing a button on top of another
curX++;
}
else
{
newButton.Location = new System.Drawing.Point((curX * 55) + 10, curY * 55);
curX++;
}
newButton.UseVisualStyleBackColor = true;
newButton.Click += new System.EventHandler(this.removeThisButton);
buttons.Add(newButton);
this.Controls.Add(newButton);
我有事件监听器的设置,但由于发件人没有关于按钮本身的实际信息,我不知道如何摆脱它。
任何帮助表示赞赏!
这是一个Windows Forms应用程序吗? WPF?我想添加更多特定标签来吸引专家。 – neontapir