How to delete dynamically-created controls in vb.net? -
i have program creates control(textboxes, progressbars, labels, timers) dynamically. created button when clicked, erase created controls on form. what's code this?
when creating controls keep references around. example can use list global variable.
dim mycontrols list(of control)
when create controls add them form's control collection , list
mycontrols = new list(of control) [...] me.controls.add(newcontrol) mycontrols.add(newcontrol)
do delete controls remove them form , dispose them (free ressources)
for each c control in mycontrols me.controls.remove(c) c.dispose() next
you can because controls reference types. means objects in both mycontrols
list , ones displayed on form point same instance , can therefore dispose them afterwards.
Comments
Post a Comment