I am generating a RichTextBox and a button with another button. When the generated button is clicked, I want to delete the RichTextBox and itself.
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++;
}
text.Dispose();anddelete.Dispose();to get rid of them. Simply callingthis.Controls.Remove(...)is not enough since it would keep the controls in memory.