salman
salman

Reputation: 565

how to remove a button dynamically in C#?

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

Answers (2)

SLaks
SLaks

Reputation: 887459

You can call someContainer.Controls.Remove(someControl).

Alternatively, you can just Dispose() the control.

Upvotes: 3

Oded
Oded

Reputation: 499042

You need to remove the reference from the Controls collection that holds them.

frm.Controls.Remove(button1);

Upvotes: 4

Related Questions