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?
You can call someContainer. Controls. Remove(someControl) . Alternatively, you can just Dispose() the control.
To add a control to a collection programmaticallyCreate an instance of the control to be added. Set properties of the new control. Add the control to the Controls collection of the parent control. The following code example shows how to create an instance of the Button control.
Pass the Clear method a control type (TextBox, Label... etc) and a control collection, and it will clear all text from controls that implement ITextBox.
You need to remove the reference from the Controls
collection that holds them.
frm.Controls.Remove(button1);
You can call someContainer.Controls.Remove(someControl)
.
Alternatively, you can just Dispose()
the control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With