这可能很简单,但我的问题是我需要在单击其中一个按钮时删除两个按钮。目前,我的代码将在单击第三个按钮时创建这两个按钮。我想要的是这些选项之一做某事(我已经做过),一旦完成,让这些按钮再次消失。下面是创建两个按钮的代码:
private void btnRandom_Click(object sender, EventArgs e)
{
Button d = new Button();
Button c = new Button();
d.Text = "Dice";
c.Text = "Chance Card";
d.Name = "btnDice";
c.Name = "btnCC";
d.Location = new Point(btnRandom.Location.X, btnRandom.Location.Y + 30);
c.Location = new Point(btnRandom.Location.X, btnRandom.Location.Y + 60);
d.Click += new EventHandler(d_Click);
c.Click += new EventHandler(c_Click);
this.Controls.Add(d);
this.Controls.Add(c);
}
以下是我删除此按钮的失败尝试
private void d_Click(object sender, EventArgs e)
{
this.Controls.Remove(btnDice); // This doesnt work
}