你可以用每个按钮的Tag属性记录每个按钮的唯一信息,然后在删除的时候,对按钮遍历,找符合条件的Tag信息的按钮进行删除即可。

解决方案 »

  1.   

    void buttonClick(object sender, System.EventArgs e)
    {
    foreach (Control cc in this.Controls)
    {

    if (cc.Focused==true)
        cc.Dispose();

    }
    }
      

  2.   

    把下面事件挂在你添加的按钮上
    private void button_Click(object sender, System.EventArgs e)
    {
    Button btn = sender as Button;
    btn.Dispose();
    }
      

  3.   

    private void button1_Click(object sender,System.EventArgs e)
    {
    if(x>=350)
    {x=-2;
    y+=30;}

    this.temp = new System.Windows.Forms.Button();
    temp.Location=new Point(x,y);
    temp.Size = new System.Drawing.Size(80, 30);
      this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {this.temp});
        x+=80;
              


    这是小弟写的程序  每次都生成叫temp的按钮 那么froeach语句的的时候 那个数组在哪呢  还有 这里所有的按钮都叫temp 不重复或者只有一个呢 高手们请指点 完成这个工作 我就可以休息了 给分
      

  4.   

    那么你可以这样做:
    首先在你的代码里再添加这样一条语句,例如添加在
    temp.Size = new System.Drawing.Size(80, 30);
    这条语句后面:
    temp.Click += new System.EventHandler(this.bb_Click);
    然后加进这个函数就可实现你要的功能了:private void bb_Click(object sender, System.EventArgs e)
    {
    Button bb=(Button)sender;
    this.groupBox1.Controls.Remove(bb);
    }