我正在生成一个RichTextBox和一个带有另一个按钮的按钮。单击生成的按钮后,我要删除RichTextBox及其本身。
static int i = 1;
private void generate_Click(object sender, EventArgs e)
{
RichTextBox text = new RichTextBox();
Button delete = new Button();
this.Controls.Add(text);
this.Controls.Add(delete);
i++;
}
答案 0 :(得分:0)
您可以从这样的表单中删除控件:
private void generate_Click(object sender, EventArgs e)
{
RichTextBox text = new RichTextBox();
Button delete = new Button();
this.Controls.Add(text);
this.Controls.Add(delete);
i++;
//---- Remove Part --------
this.Controls.Remove(text);
//------------------------
}
希望对您有帮助。
答案 1 :(得分:0)
您可以在表单中声明字段
RichTextBox m_Control;
然后分配
private void generate_Click(object sender, EventArgs e)
{
RichTextBox text = new RichTextBox();
Button delete = new Button();
m_Control = text;
this.Controls.Add(text);
this.Controls.Add(delete);
i++;
}
当您需要删除它时,可以做
this. Controls. Remove(m_Control) ;