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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -