【发布时间】:2013-09-10 21:38:07
【问题描述】:
我正在使用 C# windows 窗体,需要一些帮助。我有一个按钮可以创建其他按钮并将它们添加到列表“按钮”中。我需要让每个创建的按钮在单击时自行销毁。
//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 窗体应用程序吗? WPF?我想添加更具体的标签以帮助吸引专家。
标签: c# winforms visual-studio