Reputation: 565
i have added a button
and number of textBox
dynamically in my C# winform app. how can i remove them dynamically? specially if i have number of same controls?
Upvotes: 5
Views: 11836
Reputation: 887459
You can call someContainer.Controls.Remove(someControl)
.
Alternatively, you can just Dispose()
the control.
Upvotes: 3
Reputation: 499042
You need to remove the reference from the Controls
collection that holds them.
frm.Controls.Remove(button1);
Upvotes: 4